Skip to content

fix: remove invalid state: 'normal' from chrome.windows.create()#559

Merged
jackwener merged 2 commits intojackwener:mainfrom
Cjy-CN:fix/chrome-146-windows-create-state
Mar 28, 2026
Merged

fix: remove invalid state: 'normal' from chrome.windows.create()#559
jackwener merged 2 commits intojackwener:mainfrom
Cjy-CN:fix/chrome-146-windows-create-state

Conversation

@Cjy-CN
Copy link
Copy Markdown
Contributor

@Cjy-CN Cjy-CN commented Mar 28, 2026

Problem

When running opencli bilibili hot (or any browser-based command) on Chrome 146+, the command fails with:

Error: Invalid value for state

Running opencli doctor shows:

[OK] Daemon: running on port 19825
[OK] Extension: connected
[FAIL] Connectivity: failed (Invalid value for state)

Root Cause Analysis

1. Chrome API Documentation

According to the Chrome Extensions API documentation, the state parameter for chrome.windows.create() is described as:

state (WindowState) - Optional. Chrome 44+. The initial state of the window ('minimized', 'maximized', 'fullscreen'). Cannot be combined with 'left', 'top', 'width', or 'height'.

Key finding: The state parameter only accepts 'minimized', 'maximized', and 'fullscreen' as input values. The value 'normal' is NOT a valid input for chrome.windows.create().

2. WindowState Enum vs. state Parameter Input

While the WindowState enum definition includes "normal":

WindowState Enum:
  "normal" - Normal window state
  "minimized" - Minimized window state
  "maximized" - Maximized window state
  "fullscreen" - Fullscreen window state

This enum is used for reading window state (return value), not for setting window state during creation.

3. Chrome 146 Behavior Change

Chrome 146 (tested on 146.0.7680.165) now enforces stricter validation on the state parameter. Previous Chrome versions may have silently ignored invalid state values, but Chrome 146 throws an error.

4. The Bug

In extension/src/background.ts:163-170:

const win = await chrome.windows.create({
  url: BLANK_PAGE,
  focused: false,
  width: 1280,
  height: 900,
  type: 'normal',
  state: 'normal',  // ❌ Invalid: 'normal' is not an accepted input value
});

Solution

Remove the state: 'normal' parameter entirely. When state is not specified, the window defaults to 'normal' state anyway.

const win = await chrome.windows.create({
  url: BLANK_PAGE,
  focused: false,
  width: 1280,
  height: 900,
  type: 'normal',
  // No state parameter - window defaults to 'normal' state
});

Testing

Environment:

  • Chrome version: 146.0.7680.165
  • opencli version: 1.5.3

After applying the fix:

  • opencli doctor passes all checks
  • opencli bilibili hot returns results correctly
opencli v1.5.3 doctor (node v22.16.0)

[OK] Daemon: running on port 19825
[OK] Extension: connected (v1.5.3)
[OK] Connectivity: connected in 0.3s

Everything looks good!

References

Cjy-CN and others added 2 commits March 28, 2026 20:37
Chrome 146+ rejects 'normal' as an invalid value for the `state` parameter
in chrome.windows.create(). This causes the error:

    Error: Invalid value for state

Root cause analysis:
- The Chrome Extensions API documentation states that `state` parameter
  only accepts 'minimized', 'maximized', and 'fullscreen' as input values
- While WindowState enum includes 'normal', it's meant for reading window
  state, not for setting it during creation
- Chrome 146 enforces stricter validation on the `state` parameter
- When `state` is omitted, the window defaults to 'normal' state anyway

Fix: Remove the `state: 'normal'` parameter entirely. The window will
default to normal state without explicitly setting it.

Tested: `opencli doctor` and `opencli bilibili hot` now work correctly
on Chrome 146.0.7680.165.
@jackwener jackwener merged commit f9857f8 into jackwener:main Mar 28, 2026
@Cjy-CN Cjy-CN deleted the fix/chrome-146-windows-create-state branch March 28, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants