Skip to content

feat: add --tabname flag for per-tab isolation within a single daemon#1235

Open
halmisen wants to merge 3 commits intovercel-labs:mainfrom
halmisen:feature/tabname-tab-isolation
Open

feat: add --tabname flag for per-tab isolation within a single daemon#1235
halmisen wants to merge 3 commits intovercel-labs:mainfrom
halmisen:feature/tabname-tab-isolation

Conversation

@halmisen
Copy link
Copy Markdown

Summary

  • Adds a --tabname <name> global flag that routes any command to a named, persistent browser tab within the same daemon instance
  • Each named tab maintains its own isolated element ref map, active frame context, and cross-origin iframe sessions — no state bleeding between tabs
  • A new tab_name_list action returns all registered named tabs with URL, title, and liveness

Motivation

The current --session/--session-name mechanism provides isolation at the daemon/process level (separate Chrome instances). --tabname provides tab-level isolation within a single browser instance, which is useful when:

  • An AI agent drives multiple sites simultaneously (e.g. cross-referencing two pages)
  • A workflow needs several persistent, named browser contexts without the overhead of launching multiple Chrome processes
  • Tests need to interleave commands across tabs in a predictable, named fashion

How it works

agent-browser --tabname reddit open reddit.com
agent-browser --tabname hn    open news.ycombinator.com
agent-browser --tabname reddit snapshot   # isolated ref map, not polluted by hn
agent-browser tab_name_list               # list all named tabs
  • First use of a name creates a new browser tab; subsequent commands reuse it
  • If the backing page was closed externally the slot is re-created transparently
  • The daemon's shared ref_map / active_frame_id / iframe_sessions are swapped in/out around every command — all existing action handlers work unchanged (zero risk of regression for non-tabname usage)
  • AGENT_BROWSER_TAB_NAME env var is an alternative to the CLI flag

Changes

File Change
cli/src/flags.rs Add tab_name: Option<String> field + --tabname parsing + env var
cli/src/commands.rs Inject tab_name into command JSON when flag is set
cli/src/native/element.rs Add #[derive(Clone)] to RefMap (required for per-tab state save/restore)
cli/src/native/browser.rs Add find_page_index_by_target_id, switch_to_target, active_target_id helpers
cli/src/native/actions.rs Add NamedTabState, named_tabs field in DaemonState, setup/save helpers, tab_name_list action

Test plan

  • --tabname foo navigate <url> creates a new named tab and navigates it
  • Second call with same --tabname foo reuses the existing tab
  • --tabname a snapshot and --tabname b snapshot return independent ref maps
  • tab_name_list returns both tabs with correct URLs
  • Commands without --tabname continue to work exactly as before
  • Named tab with a closed backing page is re-created transparently

Background

This feature was originally built as a TypeScript implementation in the BUNotesAI/agent-browser-session fork and is re-implemented here natively for the Rust daemon.

fiver added 3 commits April 13, 2026 10:22
Adds a new --tabname <name> global flag that routes any command to a
named, persistent browser tab.  Each named tab keeps its own element
ref map, active frame context, and cross-origin iframe sessions, so
multiple tabs can be driven independently through the same daemon
without state bleeding between them.

How it works:
- --tabname creates the tab on first use; subsequent calls reuse it.
- If the backing page was closed externally the tab is re-created
  transparently.
- The daemon's shared ref_map / active_frame_id / iframe_sessions are
  swapped in/out around every command, so all existing action handlers
  work unchanged.
- A new `tab_name_list` action returns all registered named tabs with
  URL, title, and liveness.
- AGENT_BROWSER_TAB_NAME env var is an alternative to the flag.

Examples:
  agent-browser --tabname reddit open reddit.com
  agent-browser --tabname hn    open news.ycombinator.com
  agent-browser --tabname reddit snapshot   # isolated from hn tab
  agent-browser tab_name_list

This feature was originally built as a TypeScript implementation in
the BUNotesAI/agent-browser-session fork and is re-implemented here
natively for the Rust daemon.
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 14, 2026

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

A member of the Team first needs to authorize it.

i += 1;
}
}
"--tabname" => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --tabname CLI flag violates the project's mandatory kebab-case convention for multi-word CLI flags, making it inconsistent with all other flags.

Fix on Vercel

}

// Phase 4: Restore per-tab isolated state into the daemon's active slots.
if let Some(named) = state.named_tabs.get(tab_name) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a named tab's backing browser page dies and is recreated, stale element references, frame IDs, and iframe sessions from the dead page are restored to the new page, causing invalid state.

Fix on Vercel

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