Skip to content

Ready: feat: keep non-foreground tabs operable (focus-emulate + tab new --background)#1427

Open
soichisumi wants to merge 1 commit into
vercel-labs:mainfrom
soichisumi:leapinsight/operability-upstream
Open

Ready: feat: keep non-foreground tabs operable (focus-emulate + tab new --background)#1427
soichisumi wants to merge 1 commit into
vercel-labs:mainfrom
soichisumi:leapinsight/operability-upstream

Conversation

@soichisumi

Copy link
Copy Markdown

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.
  • Together they let an agent open and drive a tab in the background, without raising windows or stealing the user's current tab/focus.

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.visibilityState becomes hidden and rendering / requestAnimationFrame is 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 CDP Emulation.setFocusEmulationEnabled on the active tab.
  • tab new --background: a new flag on tab new that creates the target with CDP background: true. The tab still becomes the daemon's active page, so subsequent commands target it.
  • Unit tests for both command parsers, and docs/help updates for both.

How

  • focus-emulate on sends Emulation.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. off reverts it.
  • tab new --background passes background: true to Target.createTarget (built with serde_json::json!, matching the existing ad-hoc createTarget call), so the tab opens without foregrounding. No change to the typed CreateTargetParams, 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.
  • Built and run against a real Chrome over CDP: a background tab reports visibilityState=hidden and requestAnimationFrame ≈ 0 ticks/s; after focus-emulate on it reports visible, hasFocus()=true, and ≈60 ticks/s. tab new --background opens a tab without foregrounding it, and the new tab is still the active page for subsequent commands.
  • Docs/help updated for both new 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.

…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>
@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown
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.

@soichisumi soichisumi marked this pull request as ready for review June 8, 2026 16:46
@soichisumi soichisumi changed the title feat: keep non-foreground tabs operable (focus-emulate + tab new --background) Ready: feat: keep non-foreground tabs operable (focus-emulate + tab new --background) Jun 8, 2026
@soichisumi

soichisumi commented Jun 13, 2026

Copy link
Copy Markdown
Author

also this is needed 🙏
Cannot upgrade agent-browser wo these features #1425 #1426 #1427

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