playwright-cli
Playwright CLI with SKILLS
Playwright CLI vs Playwright MCP
This package provides CLI interface into Playwright. If you are using coding agents, that is the best fit.
-
CLI: Modern coding agents increasingly favor CLI–based workflows exposed as SKILLs over MCP because CLI invocations are more token-efficient: they avoid loading large tool schemas and verbose accessibility trees into the model context, allowing agents to act through concise, purpose-built commands. This makes CLI + SKILLs better suited for high-throughput coding agents that must balance browser automation with large codebases, tests, and reasoning within limited context windows.
-
MCP: MCP remains relevant for specialized agentic loops that benefit from persistent state, rich introspection, and iterative reasoning over page structure, such as exploratory automation, self-healing tests, or long-running autonomous workflows where maintaining continuous browser context outweighs token cost concerns. Learn more about Playwright MCP.
Key Features
- Token-efficient. Does not force page data into LLM.
Requirements
- Node.js 18 or newer
- Claude Code, GitHub Copilot, or any other coding agent.
Getting Started
Installation
npm install -g @playwright/cli@latest
playwright-cli --help
Installing skills
Claude Code, GitHub Copilot and others will use the locally installed skills.
playwright-cli install --skills
Skills-less operation
Point your agent at the CLI and let it cook. It'll read the skill off playwright-cli --help on its own:
Test the "add todo" flow on https://demo.playwright.dev/todomvc using playwright-cli.
Check playwright-cli --help for available commands.
Demo
> Use playwright skills to test https://demo.playwright.dev/todomvc/.
Take screenshots for all successful and failing scenarios.
Your agent will be running commands, but it does not mean you can't play with it manually:
playwright-cli open https://demo.playwright.dev/todomvc/ --headed
playwright-cli type "Buy groceries"
playwright-cli press Enter
playwright-cli type "Water flowers"
playwright-cli press Enter
playwright-cli check e21
playwright-cli check e35
playwright-cli screenshot
Headed operation
Playwright CLI is headless by default. If you'd like to see the browser, pass --headed to open:
playwright-cli open https://playwright.dev --headed
Sessions
Playwright CLI keeps the browser profile in memory by default. Your cookies and storage state
are preserved between CLI calls within the session, but lost when the browser closes. Use
--persistent to save the profile to disk for persistence across browser restarts.
You can use different instances of the browser for different projects with sessions. Pass -s= to
the invocation to talk to a specific browser.
playwright-cli open https://playwright.dev
playwright-cli -s=example open https://example.com --persistent
playwright-cli list
You can run your coding agent with the PLAYWRIGHT_CLI_SESSION environment variable:
PLAYWRIGHT_CLI_SESSION=todo-app claude .
Or instruct it to prepend -s= to the calls.
Manage your sessions as follows:
playwright-cli list
playwright-cli close-all
playwright-cli kill-all
Monitoring
Use playwright-cli show to open a visual dashboard that lets you see and control all running
browser sessions. This is useful when your coding agents are running browser automation in the
background and you want to observe their progress or step in to help.
playwright-cli show
The dashboard opens a window with two views:
- Session grid — shows all active sessions grouped by workspace, each with a live screencast
preview, session name, current URL, and page title. Click any session to zoom in.
- Session detail — shows a live view of the selected session with a tab bar, navigation
controls (back, forward, reload, address bar), and full remote control. Click into the viewport
to take over mouse and keyboard input; press Escape to release.
From the grid you can also close running sessions or delete data for inactive ones.
Commands
Core
playwright-cli open [url]
playwright-cli goto <url>
playwright-cli close
playwright-cli type <text>
playwright-cli click <ref> [button]
playwright-cli dblclick <ref> [button]
playwright-cli fill <ref> <text>
playwright-cli fill <ref> <text> --submit
playwright-cli drag <startRef> <endRef>
playwright-cli drop <ref> --path=<file>
playwright-cli drop <ref> --data="k=v"
playwright-cli hover <ref>
playwright-cli select <ref> <val>
playwright-cli upload <file>
playwright-cli check <ref>
playwright-cli uncheck <ref>
playwright-cli snapshot
playwright-cli snapshot --filename=f
playwright-cli snapshot <ref>
playwright-cli snapshot --depth=N
playwright-cli eval <func> [ref]
playwright-cli dialog-accept [prompt]
playwright-cli dialog-dismiss
playwright-cli resize <w> <h>
Navigation
playwright-cli go-back
playwright-cli go-forward
playwright-cli reload
Keyboard
playwright-cli press <key>
playwright-cli keydown <key>
playwright-cli keyup <key>
Mouse
playwright-cli mousemove <x> <y>
playwright-cli mousedown [button]
playwright-cli mouseup [button]
playwright-cli mousewheel <dx> <dy>
Save as
playwright-cli screenshot [ref]
playwright-cli screenshot --filename=f
playwright-cli pdf
playwright-cli pdf --filename=page.pdf
Tabs
playwright-cli tab-list
playwright-cli tab-new [url]
playwright-cli tab-close [index]
playwright-cli tab-select <index>
Storage
playwright-cli state-save [filename]
playwright-cli state-load <filename>
playwright-cli cookie-list [--domain]
playwright-cli cookie-get <name>
playwright-cli cookie-set <name> <val>
playwright-cli cookie-delete <name>
playwright-cli cookie-clear
playwright-cli localstorage-list
playwright-cli localstorage-get <key>
playwright-cli localstorage-set <k> <v>
playwright-cli localstorage-delete <k>
playwright-cli localstorage-clear
playwright-cli sessionstorage-list
playwright-cli sessionstorage-get <k>
playwright-cli sessionstorage-set <k> <v>
playwright-cli sessionstorage-delete <k>
playwright-cli sessionstorage-clear
Network
playwright-cli route <pattern> [opts]
playwright-cli route-list
playwright-cli unroute [pattern]
DevTools
playwright-cli console [min-level]
playwright-cli requests
playwright-cli request <index>
playwright-cli run-code <code>
playwright-cli run-code --filename=f
playwright-cli tracing-start
playwright-cli tracing-stop
playwright-cli video-start [filename]
playwright-cli video-chapter <title>
playwright-cli video-stop
playwright-cli show
playwright-cli show --annotate
playwright-cli generate-locator <ref>
playwright-cli highlight <ref>
playwright-cli highlight <ref> --style=
playwright-cli highlight <ref> --hide
playwright-cli highlight --hide
Open parameters
playwright-cli open --browser=chrome
playwright-cli attach --extension=chrome
playwright-cli attach --cdp=chrome
playwright-cli attach --cdp=<url>
playwright-cli detach
playwright-cli open --persistent
playwright-cli open --profile=<path>
playwright-cli open --config=file.json
playwright-cli close
playwright-cli delete-data
Snapshots
After each command, playwright-cli provides a snapshot of the current browser state.
> playwright-cli goto https://example.com
- Page URL: https://example.com/
- Page Title: Example Domain
[Snapshot](.playwright-cli/page-2026-02-14T19-22-42-679Z.yml)
You can also take a snapshot on demand using playwright-cli snapshot command. All the options below can be combined as needed.
playwright-cli snapshot
playwright-cli snapshot --filename=after-click.yaml
playwright-cli snapshot "#main"
playwright-cli snapshot --depth=4
playwright-cli snapshot e34
playwright-cli snapshot --boxes
Targeting elements
By default, use refs from the snapshot to interact with page elements.
playwright-cli snapshot
playwright-cli click e15
You can also use css selectors or Playwright locators.
playwright-cli click "#main > button.submit"
playwright-cli click "getByRole('button', { name: 'Submit' })"
playwright-cli click "getByTestId('submit-button')"
Sessions
playwright-cli -s=name <cmd>
playwright-cli -s=name close
playwright-cli -s=name delete-data
playwright-cli list
playwright-cli close-all
playwright-cli kill-all
Local installation
If global playwright-cli command is not available, try a local version via npx playwright-cli:
npx --no-install playwright-cli --version
When local version is available, use npx playwright-cli in all commands. Otherwise, install playwright-cli as a global command:
npm install -g @playwright/cli@latest
Configuration file
The Playwright CLI can be configured using a JSON configuration file. You can specify the configuration file using the --config command line option:
playwright-cli --config path/to/config.json open example.com
Playwright CLI will load config from .playwright/cli.config.json by default so that you did not need to specify it every time.
Configuration file schema
{
browser?: {
browserName?: 'chromium' | 'firefox' | 'webkit';
isolated?: boolean;
userDataDir?: string;
launchOptions?: playwright.LaunchOptions;
contextOptions?: playwright.BrowserContextOptions;
cdpEndpoint?: string;
cdpHeaders?: Record<string, string>;
cdpTimeout?: number;
remoteEndpoint?: string;
initPage?: string[];
initScript?: string[];
},
saveVideo?: {
width: number;
height: number;
};
outputDir?: string;
outputMode?: 'file' | 'stdout';
console?: {
level?: 'error' | 'warning' | 'info' | 'debug';
},
network?: {
allowedOrigins?: string[];
blockedOrigins?: string[];
};
testIdAttribute?: string;
timeouts?: {
action?: number;
navigation?: number;
};
allowUnrestrictedFileAccess?: boolean;
codegen?: 'typescript' | 'none';
}
Configuration via env
PLAYWRIGHT_MCP_ALLOWED_HOSTS comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check. |
PLAYWRIGHT_MCP_ALLOWED_ORIGINS semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all. Important: does not serve as a security boundary and does not affect redirects. |
PLAYWRIGHT_MCP_ALLOW_UNRESTRICTED_FILE_ACCESS allow access to files outside of the workspace roots. Also allows unrestricted access to file:// URLs. By default access to file system is restricted to workspace root directories (or cwd if no roots are configured) only, and navigation to file:// URLs is blocked. |
PLAYWRIGHT_MCP_BLOCKED_ORIGINS semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed. Important: does not serve as a security boundary and does not affect redirects. |
PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERS block service workers |
PLAYWRIGHT_MCP_BROWSER browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge. |
PLAYWRIGHT_MCP_CAPS comma-separated list of additional capabilities to enable, possible values: vision, pdf. |
PLAYWRIGHT_MCP_CDP_ENDPOINT CDP endpoint to connect to. |
PLAYWRIGHT_MCP_CDP_HEADERS CDP headers to send with the connect request, multiple can be specified. |
PLAYWRIGHT_MCP_CDP_TIMEOUT timeout for the CDP connection. |
PLAYWRIGHT_MCP_CONFIG path to the configuration file. |
PLAYWRIGHT_MCP_CONSOLE_LEVEL level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels. |
PLAYWRIGHT_MCP_DEVICE device to emulate, for example: "iPhone 15" |
PLAYWRIGHT_MCP_EXECUTABLE_PATH path to the browser executable. |
PLAYWRIGHT_MCP_EXTENSION Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed. |
PLAYWRIGHT_MCP_GRANT_PERMISSIONS List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write". |
PLAYWRIGHT_MCP_HEADLESS whether to run browser in headless mode, headless by default. |
PLAYWRIGHT_MCP_IGNORE_HTTPS_ERRORS ignore https errors |
PLAYWRIGHT_MCP_INIT_PAGE path to TypeScript file to evaluate on Playwright page object |
PLAYWRIGHT_MCP_INIT_SCRIPT path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times. |
PLAYWRIGHT_MCP_ISOLATED keep the browser profile in memory, do not save it to disk. |
PLAYWRIGHT_MCP_SANDBOX whether to enable the browser sandbox. |
PLAYWRIGHT_MCP_OUTPUT_DIR path to the directory for output files. |
PLAYWRIGHT_MCP_PROXY_BYPASS comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com" |
PLAYWRIGHT_MCP_PROXY_SERVER specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080" |
PLAYWRIGHT_MCP_SAVE_TRACE Whether to save the Playwright Trace of the session into the output directory. |
PLAYWRIGHT_MCP_SAVE_VIDEO Whether to save the video of the session into the output directory. For example "--save-video=800x600" |
PLAYWRIGHT_MCP_SECRETS_FILE path to a file containing secrets in the dotenv format |
PLAYWRIGHT_MCP_STORAGE_STATE path to the storage state file for isolated sessions. |
PLAYWRIGHT_MCP_TEST_ID_ATTRIBUTE specify the attribute to use for test ids, defaults to "data-testid" |
PLAYWRIGHT_MCP_TIMEOUT_ACTION specify action timeout in milliseconds, defaults to 5000ms |
PLAYWRIGHT_MCP_TIMEOUT_NAVIGATION specify navigation timeout in milliseconds, defaults to 60000ms |
PLAYWRIGHT_MCP_USER_AGENT specify user agent string |
PLAYWRIGHT_MCP_USER_DATA_DIR path to the user data directory. If not specified, a temporary directory will be created. |
PLAYWRIGHT_MCP_VIEWPORT_SIZE specify browser viewport size in pixels, for example "1280x720" |
Specific tasks
The installed skill includes detailed reference guides for common tasks:
- Running and Debugging Playwright tests — run, debug and manage Playwright test suites
- Request mocking — intercept and mock network requests
- Running Playwright code — execute arbitrary Playwright scripts
- Browser session management — manage multiple browser sessions
- Spec-driven testing (plan / generate / heal) — drive tests from a written spec
- Storage state (cookies, localStorage) — persist and restore browser state
- Test generation — generate Playwright tests from interactions
- Tracing — record and inspect execution traces
- Video recording — capture browser session videos
- Inspecting element attributes — get element id, class, or any attribute not visible in the snapshot