Skip to content

About

Let many Claude Code sessions use your own signed-in Chrome at once, each in its own tab, without stealing your screen. No daemon, no MCP server.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

browser-automation

Let many Claude Code sessions use your own signed-in Chrome at once, each in its own tab, without stealing your screen.

Your Chrome, your profile: cookies and extensions (password managers, etc.) survive across runs, so agents work in the sites you are already signed in to. Each session gets its own background tab, so parallel agents never fight over one active tab and never pull focus from you.

It is a CLI for AI agents (built for Claude Code, usable anywhere) that drives one shared headed Chrome with a persistent profile over per-target Chrome DevTools Protocol. No MCP server, no daemon, nothing long-lived to crash. Every command is a fresh process that connects to a single tab, acts, and exits.

Why

Driving a shared Chrome the usual way (Playwright's connectOverCDP, or an MCP server holding a browser object) has three recurring failures:

  1. It wedges. connectOverCDP enumerates every target on connect; one stuck iframe/worker or a pile of open tabs hangs the whole handshake.
  2. It can't run in parallel. All sessions share one "active tab"; concurrent agents fight over it and steal each other's (and the user's) focus.
  3. The process dies. When an MCP server's connection drops or Chrome restarts, the client needs a reconnect/restart.

This CLI fixes all three by talking per-target CDP and keeping no long-lived process:

  • Each command connects to one tab — no whole-browser enumeration, so target count never wedges it.
  • Chrome listens on no debugging port. It runs with --remote-debugging-pipe behind a small broker that launch starts, reachable only by your OS user: a 0600 socket in a 0700 folder (macOS, Linux), or a named pipe whose random name only your user can read (Windows). Login contexts get a broker each. A port has no authentication, so any program on the computer could drive a browser that listens on one.
  • Each session owns one tab by name (-s <name>); commands only touch that tab. New tabs open in the background and the CLI never activates/foregrounds a tab, so parallel sessions and the user never collide.
  • Nothing persists but the user's Chrome and a tiny per-session file. Chrome restarts? The next goto recreates the tab (sessions self-heal).

Install

npm install -g @generativereality/browser-automation
browser-automation launch     # start this user's Chrome (idempotent)
browser-automation doctor     # verify (incl. renderer capacity)

Claude Code skill (so the agent knows how to use it):

mkdir -p .claude/skills/browser/references
base=https://raw.githubusercontent.com/generativereality/browser-automation/master/skills/browser
for f in SKILL.md references/input-and-forms.md references/renderer-health.md references/contributing.md; do
  curl -fsSL "$base/$f" -o ".claude/skills/browser/$f"
done

The skill is SKILL.md plus the references/ files it points to for the long troubleshooting and hard cases; copy all of them.

…or install the plugin from the marketplace:

/plugin marketplace add generativereality/plugins
/plugin install browser-automation@generativereality

Usage

Page commands pick a tab with a selector (precedence -t > -m > -s):

  • -m <substr> — any open tab whose URL or title contains the substring (errors if ambiguous; --first to take the first). Drives tabs the user or another flow already opened — no setup.
  • -t <targetId> — an exact tab (from list).
  • -s <name> — a saved session bookmark (default $BAC_SESSION, else default).

A fourth selector, -F <substr>, is orthogonal — it descends into a tab, to a cross-origin child iframe (OOPIF) whose URL/title contains the substring (e.g. -F js.stripe.com to fill Stripe Elements). OOPIFs are first-class CDP targets, so every page command (snapshot/click/fill/ read/eval) works inside them. Same-origin iframes aren't separate targets — they're already reachable from the parent page, no -F. Discover frames with list --frames; an ambiguous -F errors (narrow it, use -t <iframeTargetId>, or --first).

Sessions are optional bookmarks, not locks — there's no one-session-one-tab rule.

# Session workflow (creates + remembers a tab)
browser-automation goto -s work https://app.example.com/login
browser-automation snapshot -s work          # -> e1, e2, e3 … refs
browser-automation fill -s work e1 "user@example.com"
browser-automation fill -s work e2 "secret" --submit
browser-automation snapshot -s work          # re-snapshot after the DOM changes
browser-automation read -s work '.account-balance'

# Drive a tab that's already open — by URL/title substring, no session needed
browser-automation list                       # see every tab: id, title, url
browser-automation read -m nordnet '.balance'
browser-automation bind -s bank -m nordnet    # …or adopt it into a session
Command What it does
launch [--status] Start this user's headed Chrome (idempotent)
doctor Diagnose Node, Chrome, targets, sessions — and renderer capacity (a browser that can no longer launch renderers passes every other check)
gc Prune stale session bookmarks and dead tabs (--dry to preview, --orphans to also close unclaimed live tabs)
list List sessions and every open tab (id, title, url)
new -s <s> [--context <name>] [url] Open a background tab for a session; --context opens it in a named login context — a separate Chrome with its own profile and window, for a second account next to your own (started on demand)
context [stop <name> | forget <name> [--delete-profile]] List login contexts and whether their Chrome is running; quit one; remove one (its profile only with --delete-profile)
goto (-s|-m|-t) <url> Navigate (session tab created if needed)
bind -s <name> (-m|-t) Adopt an already-open tab into a session
snapshot (-s|-m|-t) List interactive elements with refs (e1, e2, …)
click (-s|-m|-t) <ref> Click an element by ref
fill (-s|-m|-t) <ref> <value> [--submit] Type into a field by ref
read (-s|-m|-t) [selector] Print page text (or a CSS selector's text)
eval (-s|-m|-t) <js> Evaluate a JS expression in the tab (escape hatch)
focus (-s|-m|-t) [--raise] Make the tab report itself focused + visible, for pages that defer work while hidden (rendering, polling, charts, video). Quiet by default — no window moves; --raise genuinely brings it to the front and takes the screen
download (-s|-m|-t) (--click <ref>|--url <href>) Capture a file/CSV download, wait for completion, print the path
setfiles (-s|-m|-t) <ref> <path…> Set files on a known <input type=file> by ref (fires input/change)
upload (-s|-m|-t) --click <ref> <path…> Upload via a button that opens a file chooser (transient/custom inputs)
drop (-s|-m|-t) [--js] <ref> <path…> Drop file(s) onto a drag-and-drop zone by ref (trusted CDP drag by default; --js for a synthetic drop)
network (-s|-m|-t) [--reload|--click|--nav] [--filter --headers --body] Capture network requests (find the API, headers, response bodies)
screenshot (-s|-m|-t) [--full] [-o path] Save a PNG screenshot (viewport or full page)
close (-s|-m|-t) [--tab] Forget the session (tab stays open); --tab also closes the browser tab

How refs work

snapshot stamps data-ba-ref="eN" onto each interactive element and prints the list. Because each invocation is a separate process with no shared memory, the ref table can't live in the CLI — it lives in the page. click e7 just does querySelector('[data-ba-ref="e7"]'). Re-snapshot after any DOM change, the same one-action-per-snapshot rule as Playwright refs.

Notes & limits

  • Values are plain POSIX argv. A positional such as fill's value may contain anything — --force, a markdown --- rule, newlines — as long as the shell hands it over as one element (quote it). Only an element that begins with a dash and looks like an option (--force, -5) is read as one; to pass such a value literally, end option parsing with --: fill -t <id> -- e3 "--force". An unknown option is an error that names the offending element.
  • Interactions are JS-dispatched (element.click(), native value setter + input/change), which works on background tabs (native CDP mouse events do not reliably reach a non-foreground tab in headed Chrome). Synthetic events are not isTrusted, so a few hard anti-bot/payment flows may reject them.
  • read/snapshot see the page + same-origin frames. A cross-origin iframe is its own CDP target — reach it with -F <substr> (or -t <iframeTargetId> from list --frames); every page command then runs inside that frame.
  • File upload has two entry points (Playwright's two paths). For a static <input type=file> you can snapshot, use setfiles <ref> <path…>. For a custom "attach" button that opens a native file chooser — and reads a transient input that only exists during the chooser (App Store Connect's "Attach File", many React dropzones) — use upload --click <ref> <path…>: it intercepts the chooser and sets files on whatever input Chrome opens. Setting the static input via JS won't work there; the button uses its own throwaway input. upload judges success by the change event (reports "delivered"), since apps reset the input to 0 after consuming the file — so files=0 afterward is normal. Verify by re-snapshot/screenshot and don't blindly retry: the file may stage as a row in an attachment list (not a single chip), and each successful run adds another attachment, so retrying can silently create duplicates.
  • Drag-and-drop upload is a third path, for zones with no <input type=file> at all — a drop listener reading e.dataTransfer.files (vocalremover-style audio tools, many image/video drop zones). drop <ref> <path…> fires a genuinely-trusted CDP drag (Input.dispatchDragEvent) carrying the real files from disk: it force-fronts the tab (bringToFront + focus emulation + active lifecycle, so the renderer reports focused+visible even when the Chrome window is occluded), waits for the zone to be actionable, then dragEnter→dragOver→drop — same discipline as click --trusted. The force-front matters because drop-zone uploaders often act only inside a user activation, which CDP input can't grant on a tab the renderer considers hidden (vocalremover.org is the canonical case). --js instead dispatches a synthetic (isTrusted=false) DataTransfer drop without force-fronting/stealing focus, for zones that accept synthetic events. The <ref> is any snapshot element over the drop region — the drop bubbles to the zone/document handler, so a heading or button inside the zone works even when the zone div itself isn't snapshot-interactive. After dropping, confirm with read/screenshot and pull the result (often a download --url endpoint).
  • launch works on macOS, Linux and Windows (on Windows it needs only Node; set BROWSER_AUTOMATION_CHROME if chrome.exe is somewhere unusual). Anywhere else, start Chrome with --remote-debugging-port=<your port> --user-data-dir="<profile>" — browser-automation doctor prints the port.

Any command takes --context <name> (or BAC_CONTEXT=<name>) to act on a login context's Chrome instead of your own; a session opened in a context follows it without the flag. A new context starts with the automation profile's extensions (a password manager stays signed in) but none of its site logins, and is not signed in to Chrome; --full-copy takes the logins too and --empty-profile takes nothing. Your ordinary Chrome profile is never copied. Each context's window gets its own colour. To keep a whole project in one context, set BAC_CONTEXT in the env of that project's Claude settings.

Environment

  • BROWSER_AUTOMATION_PORT — the debugging port, used only with BROWSER_AUTOMATION_CDP and to find a Chrome of yours from before the move to the pipe (launch --restart switches it over). Defaults to one per user, not one per machine: 127.0.0.1 is machine-wide and CDP has no authentication, so a single shared port means the first account to launch owns it and every other account's automation silently drives that account's browser — same-looking page loads, in somebody else's signed-in session. Run browser-automation port for yours — the number is derived from your uid, and this file deliberately does not restate the formula: prose that repeats a rule is a copy of it, and goes stale the same way code does. doctor prints it too, and warns if another user holds it.
  • BROWSER_AUTOMATION_CDP — full CDP host, overriding the port entirely.
  • CHROME / BROWSER_AUTOMATION_CHROME — the Chrome executable launch starts, when it is not in a standard place. Otherwise: macOS /Applications then ~/Applications; Windows Program Files then %LOCALAPPDATA%; Linux google-chrome/chromium on PATH. doctor shows which.
  • BROWSER_AUTOMATION_PROFILE — Chrome profile dir for launch. Default ~/.browser-automation/chrome-profile; a profile still at the old location inside Chrome's own folder is moved there on launch (browser-automation profile --migrate to do it by hand).
  • BAC_SHOW_TAB=1 — --show on every goto/new: select the tab in its window when the automation Chrome is already in front (never raises Chrome over another app). macOS and Windows.
  • BAC_SESSION — default session name for page commands.

License

MIT — see LICENSE.

About

Let many Claude Code sessions use your own signed-in Chrome at once, each in its own tab, without stealing your screen. No daemon, no MCP server.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages