Skip to content

feat(cli): add --tab flag for tab-scoped commands#883

Open
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
mvanhorn:osc/feat-tab-scoped-commands
Open

feat(cli): add --tab flag for tab-scoped commands#883
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
mvanhorn:osc/feat-tab-scoped-commands

Conversation

@mvanhorn
Copy link
Contributor

@mvanhorn mvanhorn commented Mar 17, 2026

Summary

Add a --tab N global flag that runs a command against a specific tab without switching the active tab. Useful for multi-tab scraping workflows where you need to interact with background tabs without losing your current context.

# Take screenshot of tab 2 without switching to it
agent-browser --tab 2 screenshot

# Get the URL of tab 1
agent-browser --tab 1 url

# Click an element in tab 0
agent-browser --tab 0 click @e1

Related: #853

Evidence

Signal Source
Issue #853 "SPA Scraping Pattern: Preserving accessibility refs with tab isolation"
Issue #74 Tab management friction (tab list didn't show all tabs)
Gap Must currently switch tabs to run commands, losing active tab context
Reddit r/ClaudeAI "Whats your reliable browser setup for Claude Code?" - parallel tab management is a pain point
Reddit r/AI_Agents "Built a fully autonomous system to coordinate 100+ browser automation agents"
NxCode "Parallel browser session management" identified as universal unsolved gap

Implementation

The --tab flag is parsed in flags.rs and injected as tabIndex into the command JSON in main.rs. The daemon's handle_action in actions.rs temporarily overrides the active_page_index on BrowserManager for the duration of the command, then restores the original index afterward. This means all existing handlers work with --tab without modification.

Files changed

  • cli/src/flags.rs - parse --tab N flag, add to clean_args skip list
  • cli/src/main.rs - inject tabIndex into command JSON
  • cli/src/native/actions.rs - temporarily swap active page index before/after dispatch
  • cli/src/native/browser.rs - add active_page() and set_active_page() methods
  • cli/src/commands.rs - add tab_index to test default_flags
  • cli/src/output.rs - add --tab to help text

Test plan

  • cargo fmt passes
  • cargo clippy passes
  • cargo test passes (473 tests, 0 failures)
  • Manual: agent-browser --tab 1 url returns URL of tab 1 without switching active tab
  • Manual: agent-browser --tab 0 screenshot takes screenshot of tab 0

This contribution was developed with AI assistance (Claude Code).

Add a --tab N global flag that temporarily overrides the active page
index for the duration of a single command. This lets users run commands
against specific tabs without switching the active tab context.

Example: agent-browser --tab 2 screenshot

Related: vercel-labs#853

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Mar 17, 2026

@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

… commands

- Return error_response when --tab N is out of range instead of silently
  running against the wrong tab
- Skip active page restore after tab_close/tab_new/tab_switch since these
  commands intentionally change the active tab
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