Ready: feat: keep non-foreground tabs operable (focus-emulate + tab new --background)#1427
Open
soichisumi wants to merge 1 commit into
Open
Ready: feat: keep non-foreground tabs operable (focus-emulate + tab new --background)#1427soichisumi wants to merge 1 commit into
soichisumi wants to merge 1 commit into
Conversation
…ckground) When automating a browser a human is also using — or driving several tabs at once — an agent often needs to work on a tab that is not the foreground tab. Chrome backgrounds non-foreground tabs (`document.visibilityState` becomes `hidden`, rendering / requestAnimationFrame is throttled), so clicks and visibility/focus-gated handlers silently no-op. Foregrounding the tab to work around this steals the user's current tab. Two small, independent additions: - `focus-emulate <on|off>` toggles CDP `Emulation.setFocusEmulationEnabled` on the active tab, so it behaves as focused/visible (visibilityState=visible, hasFocus()=true, rendering runs) even while backgrounded — without raising the window or stealing OS focus. - `tab new --background` opens the new tab with CDP `background: true`, so it is created without foregrounding it. The tab still becomes the daemon's active page, so subsequent commands target it. Together they let an agent open and drive a tab in the background without disturbing the user. Verified against a real Chrome over CDP: a background tab goes from visibilityState=hidden / rAF≈0 to visible / rAF≈60fps after `focus-emulate on`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
@soichisumi is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Author
This was referenced Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
focus-emulate <on|off>— emulate a focused/visible page on the active tab so automation works on a backgrounded tab.tab new --background— open a new tab without foregrounding it.Why
When automating a browser that a human is also using, an agent often needs to work on a tab that is not the foreground tab. Chrome backgrounds non-foreground tabs:
document.visibilityStatebecomeshiddenand rendering /requestAnimationFrameis throttled, so clicks and visibility/focus-gated handlers silently no-op. The usual workaround — foregrounding the tab (Page.bringToFront) — steals the user's current tab, which is disruptive when a person is sharing the browser.What
focus-emulate <on|off>: a new command that toggles CDPEmulation.setFocusEmulationEnabledon the active tab.tab new --background: a new flag ontab newthat creates the target with CDPbackground: true. The tab still becomes the daemon's active page, so subsequent commands target it.How
focus-emulate onsendsEmulation.setFocusEmulationEnabled { enabled: true }to the active page's session, so it reports as focused + visible (and resumes rendering) even while backgrounded — without raising the window or taking OS focus.offreverts it.tab new --backgroundpassesbackground: truetoTarget.createTarget(built withserde_json::json!, matching the existing ad-hoccreateTargetcall), so the tab opens without foregrounding. No change to the typedCreateTargetParams, keeping the diff isolated.Test plan
cargo test --bin agent-browser— parser tests pass:test_focus_emulate_on/test_focus_emulate_off/test_focus_emulate_requires_on_or_off,test_tab_new_background/test_tab_new_background_with_url.visibilityState=hiddenandrequestAnimationFrame ≈ 0ticks/s; afterfocus-emulate onit reportsvisible,hasFocus()=true, and≈60ticks/s.tab new --backgroundopens a tab without foregrounding it, and the new tab is still the active page for subsequent commands.README.md,docs/src/app/commands/page.mdx,skill-data/core/references/commands.md,cli/src/output.rs).Note: this does not reintroduce scoped per-command tab dispatch (the removed
--tab, #1250) — there is no per-command tab routing here; both additions act on the active tab.