Skip to content

do not focus browser windows - #89

Merged
danielehrhardt merged 2 commits into
mainfrom
godmode/13-do-not-focus-browser-windows
Oct 5, 2026
Merged

danielehrhardt merged 2 commits into
mainfrom
godmode/13-do-not-focus-browser-windows

Conversation

@danielehrhardt

Copy link
Copy Markdown
Contributor

Stop agent browsers from taking the focus on macOS

The agent browser no longer jumps in front of whatever you're working in when an agent opens tabs or popups. Agents can keep opening tabs; Chrome just doesn't take the keyboard. In the end-to-end test each attempt was handed back to your app in about 4 ms, and polling every 20 ms never once caught Chrome in front.

What was causing it

  • Godmode starts the agent Chrome in the background, and that holds only until you click into its window once. After that, Chrome activates itself every time a page opens a tab or popup (target=_blank, window.open), and every time a tab is opened without the background flag.
  • Godmode's browser proxy already forces new tabs into the background, but agents can go around it. While you were working I caught one doing it: the CMO agent's Playwright script (cap.mjs → newPage()) connects straight to Chrome's debugging port. Its new tab appeared at 20:57:36.834, and the agent browser took the focus 8 ms later.
  • Dialogs, file pickers, passkey prompts, permission prompts and window.focus() did not steal focus in my tests.

What changed

  • Native focus guard (packages/core/native/macos/GodmodeComputer.swift, new guardFocus command; helper version 3). The helper watches which app is active. While an agent browser is armed, it hands any activation of that browser straight back to the app you were using.
    • Clicking one of the browser's windows yourself doesn't trigger it: the browser stays in front.
    • Activations while the guard isn't armed are left alone, so Cmd-Tab and similar still work (tested).
  • Arming (packages/core/src/browser/focusGuard.ts, started from ensureDefaultProfile):
    • When a visible agent browser starts, the guard starts too, so it already knows which app you're in.
    • Each new page tab arms the guard for 3 seconds. This catches every way a tab can be opened, including scripts that bypass the proxy.
    • Headless browsers and other platforms are not affected.
  • Test: packages/core/test/browser-focus-guard.test.ts runs against a stand-in helper.

Checks

  • Typecheck passes in all packages.
  • Core tests: 1500 pass, 4 fail. All 4 also fail on a clean origin/main: maintenance "updates wait while agents are working", updates "auto-updater turned off", and two in folders.test.ts.
  • Branch is up to date with origin/main (merged cleanly); commits are authored by Daniel Ehrhardt only.

Limitations

  • You can't Cmd-Tab into the agent browser in the 3 seconds after it opens a tab; clicking its window works anytime.
  • It only works when Godmode's macOS helper is available (it ships with the app; from source it needs the Xcode command line tools). If the helper is missing, the core logs one warning and nothing else changes.

What you need to do

  • Merge to main: you asked for a direct merge, but the task rules don't let me push, so Godmode opens the PR from this branch. Merge it when you're ready.
  • Reinstall the desktop app after merging (the update script). The fix lives in the native helper, so it only takes effect once the new build is installed.

Task #13 · done by Godmode with Godmode Bot

Chromium activates itself when a page opens a tab or popup, or when a script
connected straight to its DevTools port opens a tab in the foreground (the
background launch only holds until the human first clicks into the browser).
The native helper now guards every visible agent browser: whenever it gets a
new page, an activation the human didn't make by clicking one of its windows
is handed straight back to the app they were using.
@danielehrhardt
danielehrhardt merged commit 263629e into main Oct 5, 2026
7 of 8 checks passed
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.

1 participant