Skip to main content

CLI Reference

playwright-cli commands

Search by command, option, or keyword, or jump straight to a group.

Quick group filters

Installation & setup

3 commands

Install the CLI, add skills, and verify the command is available.

Install the CLI

Install the latest global playwright-cli binary.

npm install -g @playwright/cli@latest

Install skills

Add the local skill files your coding agent can read.

playwright-cli install --skills

Verify the install

Check that the CLI is available and list the current commands.

playwright-cli --help

Core

24 commands

Open pages, interact with elements, capture snapshots, and evaluate code.

Open a page

Open the browser and optionally navigate to a URL. Add options like `--headed` when needed.

playwright-cli open [url]

Option example

Open with a visible browser window while you inspect the flow.

playwright-cli open https://demo.playwright.dev/todomvc/ --headed

Go to a URL

Navigate the current page to a new address.

playwright-cli goto <url>

Close the page

Close the active page.

playwright-cli close

Type text

Type into the currently focused editable element.

playwright-cli type <text>

Click an element

Perform a click on a page element.

playwright-cli click <ref> [button]

Double click

Perform a double click on a page element.

playwright-cli dblclick <ref> [button]

Fill text

Replace the element value with text.

playwright-cli fill <ref> <text>

Fill and submit

Fill text and press Enter in one step.

playwright-cli fill <ref> <text> --submit

Drag and drop

Drag from one element ref to another.

playwright-cli drag <startRef> <endRef>

Drop a file

Drop a file from outside the page onto an element.

playwright-cli drop <ref> --path=<file>

Drop data

Drop key-value data onto an element.

playwright-cli drop <ref> --data="k=v"

Hover

Hover over an element on the page.

playwright-cli hover <ref>

Select an option

Choose a value in a dropdown.

playwright-cli select <ref> <val>

Upload files

Upload one or more files.

playwright-cli upload <file>

Check

Check a checkbox or radio button.

playwright-cli check <ref>

Uncheck

Uncheck a checkbox or radio button.

playwright-cli uncheck <ref>

Snapshot the page

Capture a page snapshot to get element refs.

playwright-cli snapshot

Save a named snapshot

Write a snapshot to a specific file.

playwright-cli snapshot --filename=f

Snapshot an element

Capture a snapshot for a single element.

playwright-cli snapshot <ref>

Limit snapshot depth

Trim snapshot depth for faster output.

playwright-cli snapshot --depth=N

Evaluate JavaScript

Run a JavaScript expression on the page or element.

playwright-cli eval <func> [ref]

Accept a dialog

Accept the current dialog, optionally with prompt text.

playwright-cli dialog-accept [prompt]

Dismiss a dialog

Dismiss the current dialog.

playwright-cli dialog-dismiss

Resize the window

Resize the browser window.

playwright-cli resize <w> <h>

Navigation

3 commands

Move through browser history and refresh the current page.

Go back

Go to the previous page in history.

playwright-cli go-back

Go forward

Go to the next page in history.

playwright-cli go-forward

Reload

Reload the current page.

playwright-cli reload

Keyboard

3 commands

Send keyboard input and hold or release specific keys.

Press a key

Press a single key such as Enter or ArrowLeft.

playwright-cli press <key>

Key down

Hold a key down.

playwright-cli keydown <key>

Key up

Release a key.

playwright-cli keyup <key>

Mouse

4 commands

Drive the mouse directly with coordinates, buttons, and wheel input.

Move the mouse

Move the cursor to a specific position.

playwright-cli mousemove <x> <y>

Mouse down

Press a mouse button down.

playwright-cli mousedown [button]

Mouse up

Release a mouse button.

playwright-cli mouseup [button]

Mouse wheel

Scroll the mouse wheel.

playwright-cli mousewheel <dx> <dy>

Save as

4 commands

Capture screenshots and PDFs for review or sharing.

Take a screenshot

Capture the current page or a single element.

playwright-cli screenshot [ref]

Save a named screenshot

Save a screenshot with a specific filename.

playwright-cli screenshot --filename=f

Save as PDF

Export the current page as a PDF.

playwright-cli pdf

Save a named PDF

Export a PDF with a specific filename.

playwright-cli pdf --filename=page.pdf

Tabs

4 commands

Create, list, switch, and close browser tabs.

List tabs

Show all open tabs.

playwright-cli tab-list

Open a new tab

Create a new tab and optionally navigate to a URL.

playwright-cli tab-new [url]

Close a tab

Close the current tab or a tab by index.

playwright-cli tab-close [index]

Select a tab

Switch to a tab by index.

playwright-cli tab-select <index>

Storage

17 commands

Work with storage state, cookies, localStorage, and sessionStorage.

Save storage state

Save the current storage state to a file.

playwright-cli state-save [filename]

Load storage state

Restore storage state from a file.

playwright-cli state-load <filename>

List cookies

List cookies, optionally for a specific domain.

playwright-cli cookie-list [--domain]

Get a cookie

Read a cookie by name.

playwright-cli cookie-get <name>

Set a cookie

Create or update a cookie value.

playwright-cli cookie-set <name> <val>

Delete a cookie

Delete a cookie by name.

playwright-cli cookie-delete <name>

Clear cookies

Remove all cookies.

playwright-cli cookie-clear

List localStorage

List localStorage entries.

playwright-cli localstorage-list

Get localStorage

Read a localStorage value by key.

playwright-cli localstorage-get <key>

Set localStorage

Write a localStorage value.

playwright-cli localstorage-set <k> <v>

Delete localStorage

Delete a localStorage entry.

playwright-cli localstorage-delete <k>

Clear localStorage

Remove all localStorage entries.

playwright-cli localstorage-clear

List sessionStorage

List sessionStorage entries.

playwright-cli sessionstorage-list

Get sessionStorage

Read a sessionStorage value by key.

playwright-cli sessionstorage-get <k>

Set sessionStorage

Write a sessionStorage value.

playwright-cli sessionstorage-set <k> <v>

Delete sessionStorage

Delete a sessionStorage entry.

playwright-cli sessionstorage-delete <k>

Clear sessionStorage

Remove all sessionStorage entries.

playwright-cli sessionstorage-clear

Network

3 commands

Mock, inspect, and remove network routes.

Add a route

Mock matching network requests.

playwright-cli route <pattern> [opts]

List routes

Show active network routes.

playwright-cli route-list

Remove routes

Remove one route or all matching routes.

playwright-cli unroute [pattern]

Monitoring

2 commands

Open the visual dashboard for live review and UI feedback.

Open the dashboard

Launch the visual dashboard for the current browser session.

playwright-cli show

Open annotated review mode

Launch the dashboard for design feedback and UI review.

playwright-cli show --annotate

DevTools

15 commands

Inspect console output, requests, traces, videos, locators, and highlights.

List console messages

Show console messages, optionally filtered by minimum level.

playwright-cli console [min-level]

List requests

Show all requests since the page loaded.

playwright-cli requests

Inspect one request

Show details for a specific request.

playwright-cli request <index>

Run inline code

Run a Playwright code snippet.

playwright-cli run-code <code>

Run code from a file

Run a Playwright code file.

playwright-cli run-code --filename=f

Start tracing

Begin trace recording.

playwright-cli tracing-start

Stop tracing

Stop trace recording.

playwright-cli tracing-stop

Start video

Begin video recording for the session.

playwright-cli video-start [filename]

Add video chapter

Insert a chapter marker into the recording.

playwright-cli video-chapter <title>

Stop video

Stop video recording.

playwright-cli video-stop

Generate a locator

Generate a Playwright locator from an element ref.

playwright-cli generate-locator <ref>

Highlight an element

Show a persistent highlight overlay.

playwright-cli highlight <ref>

Highlight with custom style

Apply a custom CSS highlight style.

playwright-cli highlight <ref> --style=

Hide one highlight

Remove the highlight from a specific element.

playwright-cli highlight <ref> --hide

Hide all highlights

Remove every highlight from the page.

playwright-cli highlight --hide

Open parameters

10 commands

Launch with a specific browser, profile, config, or attached session.

Open with a browser

Use a specific browser channel.

playwright-cli open --browser=chrome

Attach with extension

Connect through the Playwright browser extension.

playwright-cli attach --extension=chrome

Attach by channel

Attach to a running Chrome or Edge instance by channel.

playwright-cli attach --cdp=chrome

Attach by endpoint

Attach through a CDP endpoint URL.

playwright-cli attach --cdp=<url>

Detach

Detach and leave the external browser running.

playwright-cli detach

Use a persistent profile

Start with a persistent browser profile.

playwright-cli open --persistent

Use a custom profile path

Start with a specific profile directory.

playwright-cli open --profile=<path>

Use a config file

Start with an explicit config file.

playwright-cli open --config=file.json

Close the browser

Close the browser process.

playwright-cli close

Delete stored data

Delete user data for the default session.

playwright-cli delete-data

Snapshots

6 commands

Capture on-demand snapshots with filename, depth, selector, and box options.

Default snapshot

Save a timestamped snapshot file.

playwright-cli snapshot

Named snapshot

Save a snapshot with a stable filename.

playwright-cli snapshot --filename=after-click.yaml

Snapshot a selector

Capture just one element instead of the full page.

playwright-cli snapshot "#main"

Limit snapshot depth

Create a shallower snapshot for faster workflows.

playwright-cli snapshot --depth=4

Snapshot by ref

Capture a specific element using its ref.

playwright-cli snapshot e34

Include element boxes

Include bounding boxes for each element.

playwright-cli snapshot --boxes

Targeting elements

5 commands

Interact with refs, CSS selectors, role locators, and test IDs.

Get refs first

Capture a snapshot so you can target elements by ref.

playwright-cli snapshot

Click by ref

Interact with an element using the snapshot ref.

playwright-cli click e15

Click by CSS selector

Target an element with a CSS selector.

playwright-cli click "#main > button.submit"

Click by role locator

Target an element with a Playwright role locator.

playwright-cli click "getByRole('button', { name: 'Submit' })"

Click by test ID

Target an element with a Playwright test ID.

playwright-cli click "getByTestId('submit-button')"

Sessions

7 commands

Run commands in named sessions and manage all open browser sessions.

Run in a named session

Run any command inside a named session.

playwright-cli -s=name <cmd>

Close one named session

Stop a named browser session.

playwright-cli -s=name close

Delete one named session

Delete user data for a named browser.

playwright-cli -s=name delete-data

Use the session env var

Set the session name through the shell environment.

PLAYWRIGHT_CLI_SESSION=bug-bash playwright-cli open https://example.com

List sessions

Show all active sessions.

playwright-cli list

Close all sessions

Close every open browser.

playwright-cli close-all

Kill all sessions

Force kill every browser process.

playwright-cli kill-all

Local installation

2 commands

Use the local CLI with npx when the global command is not available.

Check the local CLI

Verify that a local install is available through npx.

npx --no-install playwright-cli --version

Fallback global install

Install the global CLI if the local version is missing.

npm install -g @playwright/cli@latest

Configuration

1 command

Run commands with an explicit JSON config file.

Use a config file

Pass a config file path on the command line.

playwright-cli --config path/to/config.json open example.com