Skip to content

macOS: Chrome steals window focus on every CDP command #1254

@pavnaumenko-fl

Description

@pavnaumenko-fl

Description

When using chrome-devtools-mcp on macOS, Chrome steals window focus from the active application (terminal, VS Code, etc.) on virtually every MCP tool call — including read-only operations like take_screenshot, list_pages, and select_page (with bringToFront omitted/false).

This makes the MCP very disruptive to use in AI coding agents (Claude Code, Cursor, etc.) where the user is working in their IDE/terminal while the agent interacts with Chrome in the background.

Environment

  • OS: macOS (Sonoma)
  • chrome-devtools-mcp: 0.20.3
  • Connection mode: --autoConnect
  • MCP client: Claude Code (CLI)

Steps to reproduce

  1. Open Chrome with remote debugging enabled
  2. Start chrome-devtools-mcp with --autoConnect
  3. Focus a different application (e.g., VS Code terminal)
  4. Call any MCP tool (e.g., take_screenshot, select_page, list_pages)
  5. Observe: Chrome window activates and steals focus from the current application

What I expected

Read-only CDP operations (screenshots, snapshots, page listing) should not activate the Chrome window. Only explicit user-facing actions (like bringToFront: true) should change window focus.

Workarounds attempted (none worked)

  • bringToFront: false on select_page — helps for that specific call, but other tools still steal focus
  • macOS Spaces — moving Chrome to a separate virtual desktop; Chrome still gets activated
  • PostToolUse hook with osascript to refocus the terminal — causes visible blinking (Chrome activates then terminal activates), worse UX than the original problem
  • Opening a new Chrome window in a separate Space — same result, Chrome as an app gets activated

Root cause

This appears to be a Chromium-level issue where CDP WebSocket communication triggers macOS window activation. Related Chromium bugs (open for 10+ years):

Possible solutions

  • Add a --no-activate or --background server flag that suppresses window activation during CDP communication
  • Use headless CDP session for read-only operations where possible
  • Investigate which specific CDP commands trigger macOS NSApplication activate and avoid them for non-interactive tools
  • Add background: true / focus: false parameters to Target.createTarget calls where applicable

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions