Skip to content

[Bug]: Agent browser automation (orca tab create/switch) forcibly steals Windows foreground focus — no setting or flag to disable #16674

Description

@xdoli2008

Summary

When a coding agent drives the built-in Orca browser via the CLI (core workflow for browser-automation tasks), the Orca main window forcibly steals the Windows foreground focus on every tab create/switch, interrupting whatever the user is typing in other apps. There is currently no setting or flag to disable this.

Related but more specific than #13278 (which describes the symptom without a repro or root cause).

Environment

  • Orca: 1.4.188 (Windows installer)
  • OS: Windows 10/11 (focus stealing is most aggressive on Windows due to the foreground-lock workaround, see below)
  • Workflow: agent sends orca tab create / orca tab switch / orca snapshot ... from an Orca-managed terminal while the user is working in another app (IDE, browser, chat).

Steps to reproduce

  1. Focus any other application (e.g. a text editor) and start typing.
  2. From an agent terminal (or any shell), run:
    orca tab create --url https://example.com --json
    
  3. The Orca window jumps to the foreground; your keystrokes now land into Orca.
  4. Same happens on orca tab switch --index <n> while another app is focused.

Commands that do not steal focus (good): orca snapshot, orca click, orca eval, orca navigate — when targeted at an already-active tab via --page <browserPageId>.

Root cause (from app.asar of 1.4.188)

I dug into the bundled main-process bundle and found three distinct paths that force window activation, none of which are gated by a user setting:

1. focusOnCreate defaults to true when creating browser tabs

const shouldFocusOnCreate = args.focusOnCreate !== false; // default: focus

→ creating a tab focuses the renderer, which raises the main window.

2. The CDP bridge handles Page.bringToFront unconditionally

if (msg.method === "Page.bringToFront") {
    if (!this.webContents.isDestroyed()) this.webContents.focus();
    ...
}

Agent-browser tab activation (what orca tab switch drives) always triggers webContents.focus() → window raised, no "is the window currently in the background?" check.

3. activateWindow() uses a Windows-specific foreground-lock bypass

function activateWindow(window, app, platform, setTimer) {
    safelyFocusApp(app);
    safelyRevealWindow(window);
    if (platform === "win32") {
        window.moveTop();
        pulseAlwaysOnTop(window, setTimer); // setAlwaysOnTop(true) … 250ms … false
        retryFocus(window, app, setTimer);  // +100ms retry
    }
}

pulseAlwaysOnTop is a deliberate workaround for Windows' SetForegroundWindow restrictions — i.e. even when the OS tries to protect the user's foreground, Orca forces itself on top. This is reached via shouldActivateDesktopForSecondInstance(argv) → !argvRequestsServeMode(argv), so essentially every second-instance CLI invocation is eligible.

Impact

Agent-driven browser testing/verification is a headline Orca workflow, but it makes the machine unusable for anything else while the agent runs: every tab operation rips the user out of their current window. Users must either minimize Orca (downgrades to taskbar flash) or move it to another virtual desktop.

Requested behavior (any of these would fix it)

  1. CLI flag: orca tab create --no-focus / orca tab switch --no-focus (and/or a global ORCA_NO_FOCUS=1 env var) so agent-driven automation can stay fully background.
  2. Setting: a "Keep Orca in the background when agents use the browser" toggle (Settings → Browser or → General).
  3. Conditional activation: in the Page.bringToFront handler, skip webContents.focus() when the Orca window is not the foreground window at that moment (only mark the tab active internally).

Option 3 is the least invasive and keeps interactive use behaving exactly as today.

Happy to provide traces/procmon evidence if useful. Thanks for the great product — the agent browser skill itself works beautifully once focus stealing is out of the way!

Activity

  1. added theissue type on Sep 19, 2026
  2. Fanzzzd commented on Oct 4, 2026

    @Fanzzzd
    Contributor

    I went through the open, closed and merged PRs that change how the in-app browser takes focus, to see how they relate to this issue. I wrote one of them (#24047), so I've kept this to what each PR changes and left out recommendations.

    The three paths described in this issue, and which PRs change them

    Path from this issue PRs that change it
    1. focusOnCreate defaults to true None found
    2. Page.bringToFront calls webContents.focus() Only indirectly by #24047, for offscreen pages (see below)
    3. activateWindow() on second-instance activation, with the Windows always-on-top pulse None for CLI invocations. #17347 (merged) skips activation only for test and automated launches (ORCA_BACKGROUND_LAUNCH, e2e)

    PRs about agent input landing in the wrong place or moving the user's focus

    PR Approach Size State
    #7041 Replays DOM.focus between the native webContents.focus() and Input.insertText, so fill and type reach the intended element +650/-126 Merged
    #10376 Turns on CDP focus emulation, so pages that report document.hasFocus() === false accept inserted text +111/-2 Open
    #10875 Saves the focused host WebContents before synthetic mouse presses and gives focus back afterwards +236/-61 Open
    #11732 Saves focus, focuses the guest for CDP input, restores focus afterwards +784/-19 Closed; to be superseded under this issue
    #13231 type and keypress with --page dispatch through the page's debugger instead of the OS-focused helper +299/-23 Open
    #17812 Same routing as #13231, scoped to #12912 +414/-23 Open
    #23895 Focuses the page before keypress, as click does +585/-10 Open
    #10549 Opens the browser in a split beside a live agent and parks inactive automation overlays off-screen +358/-29 Open
    #24047 Experimental setting: browser pages render offscreen, never hold native focus, and take all input over CDP. webContents.focus() on such a page targets its hidden host window, which Electron does not raise +7505/-229 Open, draft

    PRs for user-initiated focus, not agent-driven: #20892, #24364, #22271, #18834.

    Differences between the approaches

    What none of them cover

    None of these PRs changes path 1 or path 3 for CLI-driven tab create / tab switch, which is the Windows foreground behavior this issue reports. #24047 has only been tested on macOS. I haven't verified it on Windows.

  3. nwparker commented on Oct 15, 2026

    @nwparker
    Contributor

    Partial update: #28452, #28453 and #28454 (via #20595) remove focus stealing from agent page input. Page.bringToFront no longer focuses, clicks hand focus back, and keys and text go straight to the page. This issue's other two paths aren't changed: focusOnCreate and window activation on second launch. Keeping this open for the Windows foreground behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions