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 · all subjects

cli

37 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 command syntax

The playwright-cli open command opens a new browser. It can optionally navigate to a URL immediately with the syntax playwright-cli open https://example.com/

playwright-cli core interaction commands

Core commands for interacting with pages: goto navigates to a URL, type enters text, click activates an element, dblclick double-clicks, fill populates a form field with --submit flag to press Enter after filling, drag drags from one element to another, drop places files or data onto an element, hover hovers over an element, select chooses an option value, upload uploads a file, check and uncheck toggle checkboxes.

playwright-cli fill with submit option

The fill command accepts a --submit flag which presses Enter after filling the element. Example: playwright-cli fill e5 "user@example.com" --submit

playwright-cli drop command with path and data

The drop command places files or data onto an element from outside the page. Use --path=./image.png to drop a file or --data="text/plain=hello world" to drop data with a MIME type.

playwright-cli find command for searching snapshots

The find command searches the snapshot for text or a regexp and returns matching nodes with surrounding context. Syntax: playwright-cli find "Sign in" or playwright-cli find --regex "Sign (in|up)". Wrap regexp in slashes to add flags, e.g. /i for case-insensitive: playwright-cli find --regex "/sign (in|up)/i"

playwright-cli eval command for JavaScript execution

The eval command executes JavaScript on the page. Basic syntax: playwright-cli eval "document.title". Can reference elements: playwright-cli eval "el => el.textContent" e5. Can get attributes: playwright-cli eval "el => el.id" e5 or playwright-cli eval "el => el.getAttribute('data-testid')" e5

playwright-cli dialog commands

Dialog commands include dialog-accept to accept a dialog optionally with confirmation text (playwright-cli dialog-accept "confirmation text"), and dialog-dismiss to dismiss a dialog.

playwright-cli keyboard commands

Keyboard commands: press presses a key (playwright-cli press Enter), keydown holds a key (playwright-cli keydown Shift), keyup releases a key (playwright-cli keyup Shift).

playwright-cli mouse commands

Mouse commands: mousemove moves to coordinates (playwright-cli mousemove 150 300), mousedown presses the mouse button (optionally specifying button like 'right': playwright-cli mousedown right), mouseup releases the mouse button (optionally specifying button: playwright-cli mouseup right), mousewheel scrolls (playwright-cli mousewheel 0 100).

playwright-cli screenshot and pdf commands

Screenshot and pdf commands: screenshot captures the page or element, pdf captures as PDF. Both support --filename to specify output name, screenshot supports --hires for high resolution. Example: playwright-cli screenshot e5 --filename=page.png or playwright-cli pdf --filename=page.pdf

playwright-cli tab management commands

Tab commands: tab-list shows all open tabs, tab-new opens a new tab optionally navigating to a URL (playwright-cli tab-new https://example.com/page), tab-close closes the current tab or a specific tab by number (playwright-cli tab-close 2), tab-select switches to a tab by index (playwright-cli tab-select 0).

playwright-cli localStorage commands

LocalStorage commands: localstorage-list shows all localStorage items, localstorage-get retrieves a value, localstorage-set sets a value (playwright-cli localstorage-set theme dark), localstorage-delete deletes a key, localstorage-clear clears all items.

playwright-cli sessionStorage commands

SessionStorage commands: sessionstorage-list shows all sessionStorage items, sessionstorage-get retrieves a value, sessionstorage-set sets a value (playwright-cli sessionstorage-set step 3), sessionstorage-delete deletes a key, sessionstorage-clear clears all items.

playwright-cli network route commands

Route commands for mocking network responses: route intercepts requests matching a pattern with optional status code or mock body (playwright-cli route "**/*.jpg" --status=404 or playwright-cli route "https://api.example.com/**" --body='{"mock": true}'), route-list shows all active routes, unroute removes routing for a pattern (playwright-cli unroute "**/*.jpg") or all routes (playwright-cli unroute).

playwright-cli requests and request commands

The requests command lists all network requests. The request command shows details of a specific request by index (playwright-cli request 5).

playwright-cli run-code command

The run-code command executes Playwright code against the page. Syntax: playwright-cli run-code "async page => await page.context().grantPermissions(['geolocation'])" or load code from a file with --filename=script.js

playwright-cli recording commands for code generation

Recording commands: recording-start records user actions in the browser, recording-stop stops recording and prints the actions as Playwright test code.

playwright-cli video commands

Video commands: video-start begins recording video to a file (playwright-cli video-start video.webm), video-chapter adds a chapter with optional description and duration (playwright-cli video-chapter "Chapter Title" --description="Details" --duration=2000), video-stop stops video recording, video-show-actions annotates actions with duration and position (playwright-cli video-show-actions --duration=600 --position=top-right), video-hide-actions removes annotations.

playwright-cli show command for UI review

The show command launches a dashboard for UI review and design feedback. With --annotate flag, the user can annotate the page and you receive the annotated screenshot, snapshot, and notes.

playwright-cli highlight command

The highlight command shows a persistent highlight overlay for an element, optionally with custom CSS style (playwright-cli highlight e5 --style="outline: 3px dashed red"). Use --hide to remove highlights for a specific element or all page highlights (playwright-cli highlight e5 --hide or playwright-cli highlight --hide).

playwright-cli --raw option for raw output

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

playwright-cli --json option for structured output

The --json option wraps every reply as JSON for structured output.

playwright-cli open browser selection

The open command accepts --browser flag to specify the browser engine: chrome, firefox, webkit, or msedge (playwright-cli open --browser=chrome).

playwright-cli persistent profile

The open command accepts --persistent flag to use a persistent profile (by default profile is in-memory) and --profile flag to specify a custom profile directory (playwright-cli open --profile=/path/to/profile).

playwright-cli attach to browser extension

The attach command with --extension flag connects to a browser via Playwright Extension (playwright-cli attach --extension=chrome).

playwright-cli attach via CDP

The attach command connects to a running browser via Chrome DevTools Protocol (CDP). Syntax: playwright-cli attach --cdp=chrome to connect by channel name, playwright-cli attach --cdp=msedge for Edge, or playwright-cli attach --cdp=http://localhost:9222 to connect to a CDP endpoint URL.

playwright-cli detach from browser

The detach command disconnects from an attached browser while leaving the external browser running. Syntax: playwright-cli -s=msedge detach (where -s specifies the session name).

playwright-cli delete-data command

The delete-data command deletes user data for the default session or a named session (playwright-cli delete-data or playwright-cli -s=mysession delete-data).

playwright-cli Windows command line escaping for URLs with ampersands

On Windows, cmd.exe and PowerShell treat & as a command separator, truncating URLs with multiple query parameters. In cmd.exe, escape & with ^& (playwright-cli goto "https://example.com/?a=1^&b=2"). In PowerShell, use --% before the command (playwright-cli --% goto "https://example.com/?a=1&b=2").

playwright-cli snapshot format and options

The snapshot command provides a snapshot of the current browser state and saves it to a timestamped file by default. Options: --filename=after-click.yaml to save with a specific name, selector or element ref like "#main" or e34 to snapshot only that element, --depth=4 to limit snapshot depth for efficiency, --boxes to include bounding box as [box=x,y,width,height] for each element.

playwright-cli named browser sessions

Browser sessions can be named using -s=mysession flag: playwright-cli -s=mysession open example.com --persistent creates a named session. Commands on that session use the same -s flag: playwright-cli -s=mysession click e6. Named sessions persist until closed with playwright-cli -s=mysession close.

playwright-cli list and close-all commands

The list command shows all open browser sessions. The close-all command closes all browsers. The kill-all command forcefully kills all browser processes.

playwright-cli installation via npm

If playwright-cli is not available globally, use npx playwright cli in all commands. To install globally: npm install -g @playwright/cli@latest. Check version with: npx --no-install playwright --version

playwright-cli example form submission workflow

Example workflow: playwright-cli open https://example.com/form, playwright-cli snapshot, playwright-cli fill e1 "user@example.com", playwright-cli fill e2 "password123", playwright-cli click e3, playwright-cli snapshot, playwright-cli close

playwright-cli example multi-tab workflow

Example: playwright-cli open https://example.com, playwright-cli tab-new https://example.com/other, playwright-cli tab-list, playwright-cli tab-select 0, playwright-cli snapshot, playwright-cli close

playwright-cli example interactive session with annotations

Example for UI review: playwright-cli open https://example.com, playwright-cli show --annotate. The user draws boxes on the live page and types comments; you receive the annotated screenshot, the snapshot of the marked region, and the user's notes.

playwright-cli keyboard and mouse commands available

Keyboard commands include press, keydown, and keyup. Mouse commands include mousemove, mousedown, mouseup, and mousewheel. These allow direct control of keyboard and mouse input for testing purposes.

Give your agent this brain