Skip to content

browse CLI: headed mode steals window focus on every command #2148

@mecampbellsoup

Description

@mecampbellsoup

Context

The browse CLI (v0.7.3, npm install -g browse) uses Stagehand under the hood. When running in --headed mode on macOS, every CLI command (browse snapshot, browse click, browse get url, etc.) causes the Chromium window to steal focus from whatever application the user is currently working in.

The DX problem

The primary use case for --headed mode is developing and debugging browser automation flows from an AI coding agent (Claude Code, Cursor, etc.). The agent drives the browser via browse commands while the developer works in parallel — reading code, reviewing output, or doing other tasks. Every focus-steal interrupts the developer's flow.

This is a solved problem in Playwright itself: Playwright's headed mode does not steal focus on every page interaction. The difference is that Playwright passes Chrome flags like --disable-background-timer-throttling and avoids bringToFront() calls during normal interaction.

Root cause

In session-manager.js, the localBrowserLaunchOptions only passes headless:

localBrowserLaunchOptions: {
    headless: target.headless,
},

There's no way to pass additional Chromium args (e.g., --no-focus-on-navigate) or Playwright launch options through the browse CLI.

Proposed fix

Expose a way to pass additional Chrome args or Playwright launch options in local headed mode. Options:

  1. A --chrome-arg flag on browse commands: browse open https://example.com --local --headed --chrome-arg=--no-focus-on-navigate
  2. A config file or env var for default local launch options
  3. Better defaults — if headed mode is primarily for agent-driven automation, suppress focus-stealing by default (opt-in to focus with a flag instead)

Option 3 would give the best out-of-box DX for the agent use case, which is the primary audience for this tool.

Environment

  • browse v0.7.3
  • macOS (Darwin 25.5.0, arm64)
  • Node v26.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions