Playwright cli

From ai-ecoverse/slicc · View interactive version

Playwright cli is an AI agent skill from the GitHub repository ai-ecoverse/slicc. Use this whenever the user asks to browse, navigate, click, fill a form, scrape, take a screenshot, or otherwise interact with a web page. SLICC drives the browser through the `playwright-cli` shell command (also aliased as `playwright` and `puppeteer`). Read this BEFORE running any browser automati

How to use this skill

Skill file

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

Frame IDs

Common Failure Modes

support, so an exit code of 0 means everything you passed was honoured. Check <verb> --help.

fill --tab=<id> e1 -- --dash-looking.

path is --filename=<path>. Frame-prefixed refs (f1e5) clip only with click-family commands.

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):

--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:

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.

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:

the command.

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:

  1. 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, and snapshot --depth=<n> caps the tree — both much cheaper than the full tree.
  2. eval against the DOM — when you need a specific value (document.title, an attribute, computed style), eval it. Don't screenshot for facts you can extract.
  3. 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.
  4. open --view in 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:

What only the human sees:

Workflow to verify a page (when vision is actually required):

  1. serve /workspace/app — open the app (the human sees it).
  2. playwright-cli tab-list — find the tab by URL, note the targetId.
  3. playwright-cli snapshot --tab=<id> — required before screenshot, and often answers your question on its own.
  4. playwright-cli screenshot --tab=<id> --filename="$TMPDIR/shot.png" — consider --max-width to keep the file small.
  5. open --view --size medium "$TMPDIR/shot.png" — now you can see it. Use --size low when layout is all you need. Strongly prefer doing this from a scoop, not the cone.

Don't:

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.

Best practices for scoops:

  1. Track your own tab IDs. When you open a tab, capture the targetId and store it. Don't rely on tab-list to 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

```

  1. 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 / open calls.
  1. Handle "tab not found" gracefully. Another agent might close a tab between your tab-list and your command. If you get Error: No tab with id, the tab is gone — move on.
  1. Don't depend on tab count or ordering. Other agents are opening/closing tabs concurrently. Use targetIds, not positional logic.
  1. 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

screenshot <path> is an error, because that slot is the element ref.

the flag was honoured — nothing is silently dropped.

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.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.