feat: add browser context support for isolated multi-identity workflows#1340
Open
pedro-saraiva88 wants to merge 4 commits into
Open
feat: add browser context support for isolated multi-identity workflows#1340pedro-saraiva88 wants to merge 4 commits into
pedro-saraiva88 wants to merge 4 commits into
Conversation
Adds first-class support for Chrome's BrowserContext primitive (CDP Target.createBrowserContext), enabling isolated cookies, localStorage, and cache between groups of tabs within a single Chrome process. New commands: agent-browser context new [--label <name>] agent-browser context list agent-browser context close <c1|label> agent-browser tab new --context <c1|label> [url] Stable refs `c1`, `c2`, ... parallel to the existing `t1`, `t2` tab refs. Closing a context closes its tabs first; state save/load preserves per-context cookies and storage with backward-compat for old state files. Includes 9 e2e tests (isolation, cleanup, idempotency, save/load round-trip) and docs across all five locations per AGENTS.md.
The cookies and localStorage isolation tests were using `data:` URLs which trigger SecurityError when accessing storage. Switched to about:blank tabs followed by an explicit navigate to https://example.com so the storage APIs are available with a real origin. The same origin in both contexts also makes the test stronger — isolation must come from the BrowserContext, not from a different origin.
Contributor
|
@pedro-saraiva88 is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
load_storage_state was calling state::load_state(), which only restores global cookies and localStorage. Saved BrowserContext snapshots were silently dropped on launch with --state, even though state_save had written them to disk and the runtime state_load action restored them correctly. Switch to state::load_state_into_manager() so the launch-time path matches the runtime path, recreating each saved context with its label and per-context cookies/localStorage. Reported by Vercel VADE review on vercel-labs#1340.
Author
|
Thanks for catching this — fixed in 7fbcd14.
Validated with |
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
Adds first-class support for Chrome's BrowserContext primitive (CDP
Target.createBrowserContext), enabling isolated cookies, localStorage, and cache between groups of tabs within a single Chrome process. Mirrors the BrowserContext concept in Playwright and Puppeteer.Why this fits agent-browser
The project's tagline is "Browser automation CLI for AI agents." As agents move from single-task scripts to longer-running workflows, several capabilities that previously required orchestrating multiple daemons become natural inside a single process:
auth save/auth login— saved auth profiles can be loaded into named contexts (out of scope for this PR but noted as natural follow-up).The alternative today is launching multiple daemons. Each spawns its own Chrome (~200 MB). Two isolated contexts in one Chrome use ~250 MB total versus ~400 MB with two daemons — and a single CDP loop instead of N.
API
Stable refs
c1,c2, ... follow the same pattern as the existingt1,t2tab refs introduced in v0.26.0. Labels are optional and interchangeable with refs everywhere a context ref is accepted.Behaviour
Target.closeTarget), then disposes the context. Active tab index falls back gracefully when the active tab is removed.Unknown context: <ref>error, no panic.Network.getCookiesis called withbrowserContextId; localStorage is collected via a temp target opened inside each context. On load, contexts are recreated (preserving labels) and cookies/storage are restored. State files written by older versions continue to load via#[serde(default)].tab new --context c99returnsUnknown context: c99before any CDP call.Scope
In:
CreateBrowserContextParams/Result,DisposeBrowserContextParams,Network.getCookies/setCookieswithbrowserContextId)BrowserManager:ContextInfo,context_new,context_close,resolve_context,tab_new_in_context--json)Deliberately out:
auth load --context <ref>integration (future PR)Testing
Smoke verified manually: 2 contexts with same origin, cookie set in c1, c2 sees no cookie;
context close <label>closes tabs and disposes; state save → close → load preserves context labels and cookies.Documentation updates (per AGENTS.md)
cli/src/output.rs—agent-browser context --helpblockREADME.md— "Browser Contexts" section,--contextin tab optionsskill-data/core/SKILL.md— workflow section, plus newreferences/contexts.mdreference guidedocs/src/app/commands/page.mdx— section with HTML<table>for flagsContextInfo,context_new,context_close,resolve_context,tab_new_in_context,ContextSnapshotCHANGELOG.md+docs/src/app/changelog/page.mdx(within existing 0.27.0 release markers)