new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Playwright · API reference · all subjects

playwright-cli

28 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

playwright-cli open parameters for profile and persistence

Profile options for open command: --persistent to use persistent profile (default is in-memory profile), --profile=/path/to/profile to specify custom profile directory path.

playwright-cli core commands for browser interaction

The playwright-cli tool provides core commands for automating browser interactions: open to start a browser session, goto to navigate to a URL, click to click on elements (by ref, selector, or locator), type to type text, press to press keys, fill to input text with optional --submit flag to press Enter after, dblclick for double-click, hover, select to choose dropdown options, check and uncheck for checkboxes, drag to drag elements between refs, drop to drop files or data onto elements using --path or --data flags, upload for file uploads, snapshot to capture page state, find to search snapshot for text or regex patterns (with --regex flag and optional /flags/ syntax for regex modifiers), eval to execute JavaScript with optional element context, dialog-accept and dialog-dismiss for handling dialogs, and resize to change viewport dimensions.

playwright-cli navigation commands

Navigation commands available: go-back to navigate back in history, go-forward to navigate forward, and reload to reload the current page.

playwright-cli keyboard commands

Keyboard commands: press to press individual keys like Enter or ArrowDown, keydown to press and hold a key like Shift, keyup to release a held key.

playwright-cli mouse commands

Mouse commands: mousemove to move cursor to coordinates (x y), mousedown to press mouse button (optionally specify 'right' for right button), mouseup to release mouse button (optionally specify 'right'), mousewheel to scroll with deltaX and deltaY offsets.

playwright-cli screenshot and PDF commands

Save as commands: screenshot to capture page screenshot (optionally target element by ref or selector, use --filename to specify output file name, use --hires for high-resolution), pdf to save page as PDF with --filename flag.

playwright-cli tab management commands

Tab commands: tab-list to list all open tabs, tab-new to open new tab (optionally with URL), tab-close to close current tab (or specify tab index to close specific tab), tab-select to select tab by index (0-based).

playwright-cli storage state commands

Storage state commands: state-save to save browser state/cookies (optionally to specified filename like auth.json), state-load to load previously saved state from filename.

playwright-cli cookie management commands

Cookie commands: cookie-list to list all cookies (optionally filter by --domain), cookie-get to get value of specific cookie by name, cookie-set to set cookie with name and value (optionally with --domain, --httpOnly, --secure flags), cookie-delete to delete cookie by name, cookie-clear to clear all cookies.

playwright-cli localStorage commands

LocalStorage commands: localstorage-list to list all localStorage items, localstorage-get to get value by key, localstorage-set to set key-value pair, localstorage-delete to delete by key, localstorage-clear to clear all items.

playwright-cli sessionStorage commands

SessionStorage commands: sessionstorage-list to list all sessionStorage items, sessionstorage-get to get value by key, sessionstorage-set to set key-value pair, sessionstorage-delete to delete by key, sessionstorage-clear to clear all items.

playwright-cli network routing commands

Network commands: route to intercept requests matching a glob pattern with options like --status to set HTTP status code or --body to return mock response body, route-list to list all active routes, unroute to remove route matching pattern (or unroute with no pattern to remove all routes).

playwright-cli DevTools and debugging commands

DevTools commands: console to view console logs (optionally filter by severity like 'warning'), requests to list network requests, request to view details of specific request by index, run-code to execute async JavaScript code with page context (optionally load from --filename), tracing-start to begin trace recording, tracing-stop to end trace recording, recording-start to record user actions as Playwright code, recording-stop to end recording and print generated code, video-start to start video recording with filename, video-chapter to add chapter marker with title and optional --description and --duration, video-stop to end video recording, video-show-actions to annotate actions with callouts (--duration in ms, --position like 'top-right'), video-hide-actions to stop annotating actions, show with --annotate flag to launch dashboard for UI review where user can annotate page and provide feedback, generate-locator to generate Playwright locator from element ref or selector (optionally --raw for unparsed output), highlight to show persistent highlight overlay on element (optionally --style for custom CSS, --hide to remove highlight or all if no target specified).

playwright-cli --raw output option

The global --raw option strips page status, generated code, and snapshot sections from output, returning only the result value. Useful for piping command output into other tools. Commands that don't produce output return nothing.

playwright-cli --json output option

The --json flag wraps command output as JSON for structured output.

playwright-cli open parameters for browser selection

Browser selection options for open command: --browser=chrome for Chrome, --browser=firefox for Firefox, --browser=webkit for WebKit, --browser=msedge for Microsoft Edge.

playwright-cli open parameters for device emulation

Device emulation options for open command: --mobile to emulate generic mobile device (Pixel 10 for Chromium, iPhone 17 for WebKit), --device='device-name' to emulate specific device like iPhone 15.

playwright-cli attach to running browser

Attach options: attach --extension=chrome to connect via Playwright Extension, attach --cdp=chrome or attach --cdp=msedge to connect to running Chrome or Edge by channel name, attach --cdp=http://localhost:9222 to connect to running browser via CDP endpoint URL.

playwright-cli open parameters for configuration and session management

Configuration and session options: --config=my-config.json to start with config file, close to close the browser, -s=session-name to work with named browser session (e.g., 'playwright-cli -s=mysession open'), detach to detach from attached browser leaving external browser running (e.g., 'playwright-cli -s=msedge detach'), delete-data to delete user data for default session, close-all to close all browsers, kill-all to forcefully kill all browser processes.

playwright-cli snapshot options

Snapshot options: default saves with timestamp-based filename, --filename=after-click.yaml to save to specific file, target element with selector or ref like '#main' or 'e34' to snapshot element instead of whole page, --depth=N to limit snapshot depth for efficiency, --boxes to include bounding box as [x,y,width,height] for each element.

playwright-cli element targeting with refs, selectors, and locators

Elements can be targeted using: refs from snapshot like 'e15', CSS selectors like '#main > button.submit', role locators like "getByRole('button', { name: 'Submit' })", test ID locators like "getByTestId('submit-button')".

playwright-cli browser session management with -s flag

Named browser sessions created with -s flag allow concurrent browser instances: 'playwright-cli -s=mysession open example.com --persistent' creates named persistent session, all subsequent commands use -s=mysession to operate on that session, 'playwright-cli -s=mysession close' stops named browser, 'playwright-cli -s=mysession delete-data' deletes user data for that session, 'playwright-cli list' shows all open sessions.

playwright-cli global installation and npx usage

If global playwright-cli command not available, use 'npx playwright cli' locally. Check version with 'npx --no-install playwright --version'. Install globally with 'npm install -g @playwright/cli@latest'.

Windows shell escaping for URLs with query parameters

On Windows, cmd.exe and PowerShell treat & as command separator, truncating URLs with multiple query parameters before playwright-cli runs. Escape & with ^& in cmd.exe, or use --% in PowerShell: 'playwright-cli goto "https://example.com/?a=1^&b=2"' in cmd.exe or 'playwright-cli --% goto "https://example.com/?a=1&b=2"' in PowerShell.

Example: Form submission with playwright-cli

Example workflow for form submission: playwright-cli open https://example.com/form, playwright-cli snapshot to see the form, playwright-cli fill e1 "user@example.com" to fill email field, playwright-cli fill e2 "password123" to fill password field, playwright-cli click e3 to submit form, playwright-cli snapshot to verify results, playwright-cli close to finish.

Example: Multi-tab workflow with playwright-cli

Example workflow for multiple tabs: playwright-cli open https://example.com opens first tab, playwright-cli tab-new https://example.com/other opens second tab with URL, playwright-cli tab-list shows all open tabs, playwright-cli tab-select 0 switches to first tab, playwright-cli snapshot shows first tab state, playwright-cli close closes the browser.

Example: Debugging with playwright-cli console and requests

Example debugging workflow: playwright-cli open https://example.com navigates to page, playwright-cli click e4 performs click action, playwright-cli fill e7 "test" fills an input, playwright-cli console displays browser console logs, playwright-cli requests shows network requests, playwright-cli close ends session. Alternatively use tracing-start before actions, then tracing-stop to record trace.

Example: Interactive UI review with playwright-cli show --annotate

For UI review or design feedback: playwright-cli open https://example.com navigates to page, playwright-cli show --annotate launches dashboard where user draws boxes, types comments, and you receive annotated screenshot, snapshot of marked region, and user's notes.

Give your agent this brain