Skip to content

[Bug]: chrome.windows.create fails with "Invalid value for state" when creating automation window #545

@Cjy-CN

Description

@Cjy-CN

Description

When running browser commands (e.g., opencli bilibili hot), the extension fails to create the automation window
with the error:

[pre-nav] Failed to navigate to https://www.bilibili.com: Invalid value for state
Error: Invalid value for state

Steps to Reproduce

  1. Install opencli globally: npm install -g @jackwener/opencli
  2. Install the OpenCLI Browser Bridge extension in Chrome
  3. Run any browser command: opencli bilibili hot
  4. Observe the error

Expected Behavior

The automation window should be created successfully and the command should execute.

Actual Behavior

The command fails with Invalid value for state error.

Root Cause

In extension/src/background.ts, the getAutomationWindow() function creates a window with conflicting
parameters:

// Line 149-156
const win = await chrome.windows.create({
    url: BLANK_PAGE,
    focused: false,        // ❌ Problem here
    width: 1280,
    height: 900,
    type: 'normal',
    state: 'minimized',    // ❌ Conflicts with focused
});

According to https://developer.chrome.com/docs/extensions/reference/api/windows:

 focused: If true, brings the window to the front; cannot be combined with the state 'minimized'.

The focused parameter (whether true or false) cannot be used together with state: 'minimized'. This is a hard
constraint in Chrome's API.

### OpenCLI Version

1.5.2

### Node.js Version

22.x

### Operating System

Windows

### Logs / Screenshots

```shell

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions