Browser Automation via playwright-cli
Use playwright-cli (also aliased as playwright and puppeteer) via the bash tool for all browser automation.
Every tab-operating command requires --tab=<targetId>. There is no implicit "current tab". Always specify which tab you're operating on.
playwright-cli <command> --help prints that command's usage and does nothing else — safe to run before any action.
Quick Start
# 1. Open a page — note the targetId in the output
playwright-cli open https://example.com
# Output: Opened https://example.com in new tab [targetId: E9A3F...]
# 2. Take a snapshot to see the page structure and get element refs
playwright-cli snapshot --tab=E9A3F
# 3. Interact using refs from the snapshot (e.g. e5, e12)
playwright-cli click --tab=E9A3F e5
playwright-cli fill --tab=E9A3F e12 "hello world"
# 4. Each action prints "Snapshot: <path>" — read it to see what changed
playwright-cli snapshot --tab=E9A3F
Tab IDs
tab-listshows all tabs with their targetIds and a stable(tab N)number. In the extension the user's active tab is marked(active); standalone Chrome does not report it.tab-new/openreturn the new tab's targetId — capture it for subsequent commands.- Use
--tab=<targetId>on ALL commands that operate on a tab.
Frame IDs
frames --tab=<targetId>lists frame IDs. A frame ID is not a tab target ID; never pass it to--tab.- Use
--tab=<targetId> --frame=<frameId>witheval,eval-file, orsnapshotto target a child frame, including cross-origin frames. - A frame-scoped
snapshotprints only that frame's accessibility subtree. Its frame-prefixed refs (f1e5) work with every ref command exceptdrag,screenshot, andsnapshot --boxes; do not pass--frameto those commands.
Common Failure Modes
--tab <targetId> is required— you forgot--tab=<id>. Runtab-listto get IDs.is a frame ID, not a tab target ID— keep the owning tab's targetId in--taband pass the frame ID with--frame.No snapshot available— runsnapshot --tab=<id>before using refs.unknown flag "--x"/unexpected argument "y"— every subcommand rejects arguments it does not
support, so an exit code of 0 means everything you passed was honoured. Check <verb> --help.
- For free-text payloads that start with
-(e.g.fill/type/eval), put--before the text:
fill --tab=<id> e1 -- --dash-looking.
is not an element ref— a screenshot's positional is a main-frame element ref (e5); the output
path is --filename=<path>. Frame-prefixed refs (f1e5) clip only with click-family commands.
Unknown ref/is no longer on the page— that element was removed or renamed, or the page navigated. Re-runsnapshotfor current refs; a ref is never re-pointed at a different element.- Refs are tied to one tab + one page load. They do not carry across tabs, navigations, or reloads.
Element Refs
Snapshots assign short ref IDs (e1, e2, ...) to interactive elements. Use these refs with click, fill, dblclick, hover, select, check, uncheck, drag, upload, drop, and screenshot.
When present, accessibility states appear after the ref in Playwright aria-snapshot form — [checked], [checked=mixed], [expanded] / [expanded=false], [selected], [pressed], [disabled], [level=N] — so a re-snapshot shows whether a radio, disclosure, tab, or toggle changed.
A ref names one element for as long as that element stays on the page with the same role and name. When the page adds an element, it gets a new ref and the existing refs do not shift, so fill e28 …; fill e30 …; click e31 keeps hitting the elements you read. A ref whose element is gone fails loudly instead of acting on whatever took its place.
Commands
All commands below that operate on a tab require --tab=<targetId>.
Core
playwright-cli open [url] [--foreground] [--mobile] # Open tab (background by default), returns targetId
playwright-cli tab-new [url] [--foreground] [--mobile] # Same as open
playwright-cli tab-close --tab=<id> # Close tab (alias: close)
playwright-cli goto --tab=<id> <url> # Navigate tab
playwright-cli navigate --tab=<id> <url> # Alias for goto
playwright-cli snapshot --tab=<id> [--frame=<frameId>] [--no-iframes] [--filename=path] [--depth=<n>] [--boxes] # Tab tree or one frame subtree; --depth limits nesting, --boxes adds [box=x,y,w,h] rects
playwright-cli find --tab=<id> <text> # Search the snapshot for text (case-insensitive), returns matching lines + context
playwright-cli find --tab=<id> --regex=<re> # Same, with a regexp (use either text or --regex, not both)
playwright-cli eval --tab=<id> [--frame=<frameId>] <expression> [--filename=path|--output=path] # Evaluate JS in a tab/frame, incl. top-level await/return; use `--` before an expression that starts with `-`
playwright-cli eval-file --tab=<id> [--frame=<frameId>] <vfs-path> [--output=path|--filename=path] # Evaluate JS from a VFS file in a tab/frame (top-level await/return supported)
playwright-cli frames --tab=<id> # List frame IDs for --frame (not --tab)
playwright-cli resize --tab=<id> <width> <height> # Resize viewport
--foreground (or --fg) opens the new tab in the foreground — it brings the
new tab to the front and switches the user's visible/active tab to it, instead of
opening in the background.
Bringing a tab to the foreground (activate / focus / raise / switch to a tab):
- New tab →
open <url> --foreground(ortab-new <url> --fg). - Existing tab →
tab-select --tab=<targetId>, ortab-select <N>with the(tab N)number fromtab-list. Numbers stick to their tab while it is open (new tabs get the next number), so they do not shift when other agents open or close tabs.
--mobile opens the tab with generic mobile-device emulation (viewport,
device pixel ratio, touch, Android Chrome UA), sticky for the tab's lifetime —
a later resize changes only the dimensions and keeps the mobile identity.
Mobile pages are usually lighter, which saves tokens.
These two are the ONLY ways to change which tab is in front. There is no
activate, bring-to-front, or focus subcommand, and eval-ing
window.focus() does NOT work (browsers block a page from stealing foreground).
If a tab didn't come to the front, re-run tab-select / --foreground — do not
fall back to window.focus().
Interaction
playwright-cli click --tab=<id> <ref> [--modifiers=Shift,Control,Alt,Meta] # Click element
playwright-cli dblclick --tab=<id> <ref> [button] [--modifiers=...] # Double-click
playwright-cli fill --tab=<id> <ref> <text> [--submit] # Clear input + type text (--submit presses Enter); use `--` before text that starts with `-`
playwright-cli type --tab=<id> <text> [--submit] # Type into focused element (--submit presses Enter); use `--` before text that starts with `-`
playwright-cli hover --tab=<id> <ref> # Hover over element
playwright-cli select --tab=<id> <ref> <value> # Select dropdown value
playwright-cli check --tab=<id> <ref> # Check checkbox/radio
playwright-cli uncheck --tab=<id> <ref> # Uncheck checkbox/radio
playwright-cli drag --tab=<id> <startRef> <endRef> # Drag and drop
playwright-cli upload --tab=<id> [ref] <file> [file...] # Upload VFS files to file input as raw bytes (optional snapshot ref targets hidden inputs)
playwright-cli drop --tab=<id> <ref> [--path=<vfs-path>] [--data=<mime/type=value>] # Drop files/data onto element (--path drops raw bytes)
playwright-cli dialog-accept --tab=<id> [text] # Accept JS dialog
playwright-cli dialog-dismiss --tab=<id> # Dismiss JS dialog
Keyboard
playwright-cli press --tab=<id> <key> # Press key (keyDown + keyUp, e.g. Enter, Tab, Escape)
playwright-cli keydown --tab=<id> <key> # Hold key down (no paired keyUp)
playwright-cli keyup --tab=<id> <key> # Release held key (no paired keyDown)
Mouse
playwright-cli mousemove --tab=<id> <x> <y> # Move mouse to coordinates (negative coords ok, e.g. -10 20)
playwright-cli mousedown --tab=<id> [button] # Press mouse button (left/right/middle, default: left)
playwright-cli mouseup --tab=<id> [button] # Release mouse button
playwright-cli mousewheel --tab=<id> <dx> <dy> # Scroll mouse wheel (negative deltas ok, e.g. 0 -300)
Navigation
playwright-cli go-back --tab=<id> # history.back()
playwright-cli go-forward --tab=<id> # history.forward()
playwright-cli reload --tab=<id> # Reload page
Teleport
playwright-cli teleport --tab=<id> --start=<regex> --return=<regex> [--timeout=<s>]
playwright-cli teleport --list # List available follower runtimes
playwright-cli teleport --off --tab=<id> # Cancel a teleport on this tab
playwright-cli open <url> --teleport-start=<regex> --teleport-return=<regex>
playwright-cli goto --tab=<id> <url> --teleport-start=<regex> --teleport-return=<regex>
Teleport is for leader/follower tray auth handoffs. Scoped to a specific tab — only commands targeting the teleporting tab are blocked; other tabs remain operational.
--runtime is optional: without it, teleport picks the most recently active eligible follower (preferring standalone floats). Only followers that can actually serve cookies are eligible — cherry hosts, exec-only CLI followers, and any target advertising network: false are excluded, so a teleport fails fast instead of "succeeding" with zero cookies.
Screenshots
playwright-cli screenshot --tab=<id> # Save to $TMPDIR/screenshot-<ts>.png
playwright-cli screenshot --tab=<id> --filename=page.png # Save to custom path
playwright-cli screenshot --tab=<id> e5 # Clip to an element (positional = MAIN-FRAME ref, not a path)
playwright-cli screenshot --tab=<id> --fullPage # Full scrollable page (alias: --full-page)
playwright-cli screenshot --tab=<id> --max-width=800 # Downscale to a max width (png output only)
playwright-cli screenshot --tab=<id> --type=jpeg # png (default) / jpeg / webp; inferred from --filename extension
playwright-cli screenshot --tab=<id> --hires # Capture in device pixels (honors device pixel ratio)
Viewport screenshots (default, --max-width, --hires) honor the tab's current scroll position. --fullPage captures from the document origin.
An element screenshot (screenshot e5) returns that element's crop or fails
(exit 1) — typically because the snapshot went stale after a navigation or
layout change. Re-run snapshot and retry with a fresh ref; it never silently
substitutes a full-viewport frame.
A resize sticks to its tab: the viewport override is re-applied automatically
whenever the tab is re-attached, so another driver switching tabs cannot reset
it.
All playwright-cli commands share one browser, and locking is per tab:
commands on different tabs run in parallel; commands on the same tab serialize.
A slow or hung navigation stalls only its own tab. A few genuinely global
operations (tab-select, --foreground, and the attach that points the bridge
at a tab) still take a bridge-wide lock, but they are short and never wrap a
page wait. When callers queue up, commands may emit a
note: browser bridge contended — ... line on stderr with the total lock wait
and queue depth; the note says whether the wait was on this tab or
bridge-wide. Either way it is back-off guidance — stagger callers or give
each one its own tab, never re-run the command; it already ran, it was just
slow to get the lock.
Giving up cancels the command. When your bash call stops waiting — the
turn is cancelled, timeout fires, or someone runs kill <pid> — the
playwright-cli command is cancelled too instead of running on for a caller that
is gone: a queued command drops out of the tab's queue without taking the lock,
a goto waiting on a load event and a waitForSelector poll stop at once, and
a multi-step command stops before its next CDP round trip. Such a command exits
130 with a stderr line naming the step it stopped at, never 0.
Two consequences for you:
- A cancelled command may have half-landed. The CDP request already on the
wire cannot be recalled, so keys may be typed or a click delivered before the
stop. snapshot the tab and continue from what you see rather than blindly
re-running — same rule as a mid-command session reset.
background_afteralone does not cancel; it detaches, and the command
keeps running as a background job (that is what makes a long goto usable).
Use timeout or kill <pid> when you actually want it stopped.
Stale session. The bridge re-attaches automatically after a Chrome reset;
there is no need to reload the tab or open a new one. Two error shapes:
Session with given id not found— the bridge already re-attached; re-run
the command.
… was reset mid-command … the outcome is unknown— part of the command may
have landed (keys typed, a click delivered) before the session died. Do NOT
blindly re-run it: snapshot the tab first and continue from what you see.
Save As
playwright-cli pdf --tab=<id> [--filename=path] # Save page as PDF (not available in extension mode)
Viewing pages and screenshots yourself
The browser displays things to the human; open --view is what lets _you_ see them. But viewing screenshots is a last resort for the cone — every image you load eats a large chunk of the context window (a single 1280×800 PNG can run 1500+ tokens, full-page screenshots much more). Reach for cheaper signals first:
playwright-cli snapshot --tab=<id>— text accessibility tree. Use this first; it answers "what's on the page" for almost all verification tasks at a tiny fraction of the token cost. On a big page,find --tab=<id> <text>greps the snapshot and returns just the matching lines with context, andsnapshot --depth=<n>caps the tree — both much cheaper than the full tree.evalagainst the DOM — when you need a specific value (document.title, an attribute, computed style),evalit. Don't screenshot for facts you can extract.- Delegate visual inspection to a scoop. If the cone genuinely needs vision (layout regression, render fidelity, "does this look right"), spawn a scoop to take and view the screenshot — the scoop's context absorbs the tokens, and you receive its summary back. The cone's window stays clean for orchestration.
open --viewin the cone — only when the cone itself must see pixels for its current decision and steps 1–3 won't do.
What you CAN see:
open --view --size <low|medium|high|WxH> <path>— reads an image from the VFS and returns it, resized to fit the box (low256×256,medium768×768,high1536×1536).--sizeis required. Works with PNG, JPEG, GIF, WebP, SVG.playwright-cli screenshot --tab=<id> --filename=<path>+open --view --size medium <path>— screenshot a tab, then view it.screencapture --view screenshot.png— capture the user's screen via browser screen sharing.screencapture --video -V 10 clip.webm— record a timed screen/window/tab clip (WebM).playwright-cli snapshot --tab=<id>— accessibility tree (text). Use to verify content without vision.
What only the human sees:
serve <dir>— opens an app directory in a browser tab (read-only preview).- Preview URLs survive authenticated tray roves without changing their original directory, entry file, or bridge permissions. A handoff can briefly return
503; retry the same pending rove rather than minting another target. Bridge tabs reconnect automatically (their connection IDs may change). Revoked previews stay revoked, and persistent snapshots keep their original expiry rather than receiving a fresh TTL. - Persistent uploads retry safely only with the same file bytes and MIME type. Body/R2-write waits time out after 30 seconds. Unknown writes retain bounded cleanup bookkeeping (up to eight unresolved uploads per preview); expiry/revoke never makes such a preview serve again, even if a delayed write finishes later.
serve --ttl 30d <dir>— uploads an immutable snapshot that works without the leader. TTL units are wholem,h,d, orw, capped at 30 days. It implies--no-bridge, conflicts with--bridge/--max-tabs, and is limited to 1,000 files, 25 MiB per file, and 50 MiB total. Useserve --listfor mode/expiry andserve --stop <token>to revoke it early.servelimits — plan for them: a live-preview file over 25 MiB is served only through Range requests (a plain GET answers 413; media elements use ranges, so no splitting is needed), and--ttlfiles must be ≤ 25 MiB. A tray holds at most 10--ttlsnapshots (uploads in progress count); live previews have no quota. A live preview is deleted once the leader has been disconnected for 5 minutes; a snapshot lasts until its TTL. EachserveprintsPreview token: …;serve --stop <token-or-url>snapshots you no longer need, and onSnapshot limit reachedrunserve --listand stop old ones.serve --bridge <dir>— opens a driveable preview whose visitors auto-connect as live synthetic-CDP targets you can navigate/click/evaluate/screenshot via playwright. Security: opt-in only; cross-subdomain cookie risk accepted (host-only cookies isolated;Domain=.sliccy.nowcookies readable across previews). Flags:--max-tabs <N>(default 20),--quiet(suppress the first-visit announcement),--no-bridge(force read-only),--stop <token>(revoke + delete webhook). Useserve --logs [<token>] [--lines <N>]to inspect leader-memory-only connect/disconnect records without emitting a lick or waking the cone.serve --truncate [<token>]clears matching records and re-arms the first-visit announcement, so the next visit announces once. Visitor page API:window.slicc.emit(name, detail?)(fires webhook lick on cone),window.slicc.on(name, cb)(subscribes to CustomEvents you dispatch).- Media in
servepreviews plays through Range requests: live previews answerRangein ≤ 8 MiB windows, so<video>/<audio>larger than 25 MiB play and seek without splitting; only a plain full-file GET of such a file gets 413.--ttlsnapshots support Range too (their files stay ≤ 25 MiB). open <path>(no flags) — opens a file in a browser tab.imgcat <path>— displays an image in the terminal preview.
Workflow to verify a page (when vision is actually required):
serve /workspace/app— open the app (the human sees it).playwright-cli tab-list— find the tab by URL, note the targetId.playwright-cli snapshot --tab=<id>— required before screenshot, and often answers your question on its own.playwright-cli screenshot --tab=<id> --filename="$TMPDIR/shot.png"— consider--max-widthto keep the file small.open --view --size medium "$TMPDIR/shot.png"— now you can see it. Use--size lowwhen layout is all you need. Strongly prefer doing this from a scoop, not the cone.
Don't:
- Default to screenshots when a snapshot would do.
read_fileon a PNG or base64-encode to view images.imgcatorcaton screenshots expecting to see them.- Open a screenshot then screenshot that tab.
- Use
evalto check the active tab — usetab-list.
Tab Management
playwright-cli tab-list # List tabs with targetIds, (tab N), (active) marker
playwright-cli tab-new [url] # New tab, returns targetId
playwright-cli tab-close --tab=<id> # Close specific tab
playwright-cli tab-select --tab=<id> # Select (bring to front) a tab by targetId
playwright-cli tab-select <N> # ... or by its (tab N) number from tab-list
Cookies
playwright-cli cookie-list --tab=<id> [--domain=<d>] [--path=<p>] # List cookies (filter by domain/path)
playwright-cli cookie-get --tab=<id> <name> # Get cookie
playwright-cli cookie-set --tab=<id> <name> <value> [--sameSite=Strict|Lax|None] [other flags] # Set cookie
playwright-cli cookie-delete --tab=<id> <name> [--domain= --path=] # Delete cookie
playwright-cli cookie-clear --tab=<id> # Clear all cookies
Storage
playwright-cli localstorage-list --tab=<id>
playwright-cli localstorage-get --tab=<id> <key>
playwright-cli localstorage-set --tab=<id> <key> <value>
playwright-cli localstorage-delete --tab=<id> <key>
playwright-cli localstorage-clear --tab=<id>
# Same pattern for sessionstorage-*
playwright-cli state-save --tab=<id> [filename|--filename=path] # Save cookies + localStorage to JSON
playwright-cli state-load --tab=<id> <filename> # Restore from state file
Network
playwright-cli console --tab=<id> [min-level] [--clear] # List console messages (debug/log/info/warning/error)
playwright-cli requests --tab=<id> [--static] [--filter=<regex>] [--clear] # List network requests
playwright-cli request --tab=<id> <index> [--filename=path] # Full request details
playwright-cli request-headers --tab=<id> <index> # Request headers only
playwright-cli request-body --tab=<id> <index> # Request body only
playwright-cli response-headers --tab=<id> <index> # Response headers only
playwright-cli response-body --tab=<id> <index> [--filename=path] # Response body (--filename saves the exact bytes)
playwright-cli network-state-set --tab=<id> <online|offline> # Toggle network state
playwright-cli route --tab=<id> <pattern> [--status=N] [--body=text] [--content-type=type] [--header=name:value]
playwright-cli route-list --tab=<id> # List active routes
playwright-cli unroute --tab=<id> [pattern] # Remove routes (all if no pattern)
DevTools
playwright-cli generate-locator --tab=<id> <ref> # Generate Playwright locator string for element
playwright-cli highlight --tab=<id> <ref> [--style=<css>] # Highlight element with visual overlay
playwright-cli highlight --tab=<id> --hide [ref] # Remove highlight (all if no ref)
HAR Recording
playwright-cli record [url] [--filter=<js-expr>] # Open tab with network recording
playwright-cli stop-recording <recordingId> # Stop and save HAR
Multi-Agent Tab Behavior
All agents (cone + scoops) share the same tab namespace. There is no tab isolation.
tab-listshows every tab from every agent — yours, the cone's, other scoops'. The list can be noisy.- Any agent can
eval,snapshot, orcloseany tab — there are no ownership checks. - Tab counts fluctuate as other agents open and close tabs concurrently.
Best practices for scoops:
- Track your own tab IDs. When you open a tab, capture the targetId and store it. Don't rely on
tab-listto find your tabs later — other agents' tabs will be mixed in.
```bash
# Open and capture the ID
playwright-cli tab-new https://example.com
# Output: Opened https://example.com in new tab [targetId: ABC123...]
# Use ABC123 for all subsequent commands on this tab
```
- NEVER close tabs you didn't open. Tabs you don't recognize belong to the user or other agents. User tabs are off-limits unless the user explicitly asks you to close them. Only close tabs whose targetId you captured from your own
tab-new/opencalls.
- Handle "tab not found" gracefully. Another agent might close a tab between your
tab-listand your command. If you getError: No tab with id, the tab is gone — move on.
- Don't depend on tab count or ordering. Other agents are opening/closing tabs concurrently. Use targetIds, not positional logic.
- Clean up when done. Close all tabs you opened before finishing. Include this in every scoop brief:
_"Close each tab with playwright-cli tab-close --tab=<id> when done."_
Tips
- Refs are stable per element — chain actions on refs from one snapshot freely. Re-snapshot (or read the
Snapshot: <path>file an action prints) to see elements the page added. openandtab-newopen tabs in the background by default. Capture the targetId from the output. To open in the foreground add--foreground/--fg; to raise an already-open tab usetab-select --tab=<id>(ortab-select <N>).- After
goto,go-back,go-forward, orreload, take a freshsnapshot --tab=<id>: the new page has new refs. - Unexpected JavaScript dialogs are auto-dismissed on attached pages.
- Use
eval --tab=<id>for DOM operations not covered by built-in commands; save results with--filename=path. - The SLICC app tab and Chrome internal UI tabs are automatically excluded from
tab-list. fillclears and types into regular inputs, textareas, andcontenteditableelements. Use--submitto press Enter after. If the text or anevalexpression starts with-, put--before it so it is not parsed as a flag.- Negative numbers for
mousewheel/mousemoveare positionals (no--needed):mousewheel --tab=<id> 0 -300. drop --path=<vfs-path>injects the file as raw bytes; a UTF-8 text round-trip would replace every byte >= 0x80 withEF BF BD, so mp4/zip/jpg drops stay byte-exact.- Screenshots default to
$TMPDIR/screenshot-<timestamp>.png— your own scratch directory, not the shared root. Use--filename=pathto save elsewhere —
screenshot <path> is an error, because that slot is the element ref.
- Unsupported flags and extra positionals are rejected per subcommand, so a probe that exits 0 means
the flag was honoured — nothing is silently dropped.
- Use
keydown/keyupfor holding modifier keys (e.g. Shift+click:keydown Shift,click,keyup Shift). - Use
requests+response-bodyto inspect XHR/fetch responses;routeto mock or block them. - Calling the app's own backend? Use
curlwright, noteval-file. It is curl's flags run by afetch()inside the tab, so cookies, origin and session come along:curlwright -s -X POST https://app.example.com/api/items -H 'X-CSRF-Token: abc' -d '{"name":"x"}' --tab=<id>.-o <file>writes a byte-exact body, whicheval-filecannot do at all — that is the only way to pull a binary response out of a page. Without--tabit uses the tab already on that origin.curlwright --helpfor the flag list. It cancels the same way playwright-cli does — giving up exits 130 and writes no-ofile for a response nobody is reading — but the in-pagefetchis bounded by-m, not by the cancellation, so a cancelled request may still have reached the server. state-save/state-loadpersist auth state (cookies + localStorage) across sessions.- Every command is logged to
session.md(auto-snapshots and screenshot copies alongside) under/.playwright/in the cone, or your own$TMPDIR/.playwright/in a scoop.state-savewith no filename writesstorage-state.jsonthere too. pdfsaves a print-layout PDF; not available in extension mode.uploadinjects VFS files as raw bytes (a UTF-8 text round-trip would replace every byte ≥ 0x80 withEF BF BD). A leadingeN/fNeNtoken is a snapshot ref, never a filename — runsnapshotfirst; without a ref, focus the file input first. To upload a file namede2, pass./e2or an absolute path.
Low-level CDP escape hatch
For raw Chrome DevTools Protocol calls that playwright-cli doesn't wrap, send JSON-RPC directly over WebSocket with websocat:
# Discover the page's debug socket URL via the CDP HTTP endpoint
curl -s http://127.0.0.1:9222/json | jq -r '.[0].webSocketDebuggerUrl'
# Send a single CDP method, receive the response, exit
echo 'Page.navigate {"url":"https://example.com"}' \
| websocat -1 --jsonrpc --jsonrpc-omit-jsonrpc ws://127.0.0.1:9222/devtools/page/<id>
Run websocat --help for the full flag list. Use this only when playwright-cli has no wrapper for the CDP method you need.