Skip to main content

Playwright CLI

A command-line interface for browser automation designed for coding agents. Token-efficient commands and installable skills let agents balance browser automation with large codebases and reasoning within limited context windows.

Example​

$ 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 screenshot

After each command, the CLI outputs the current page state:

### Page
- Page URL: https://demo.playwright.dev/todomvc/#/
- Page Title: React - TodoMVC
### Snapshot
- [Snapshot](.playwright-cli/page-2026-02-14T19-22-42-679Z.yml)

The snapshot file contains the accessibility tree with element refs for the next command.

Key Features​

  • Token-efficient — concise CLI output avoids loading large tool schemas into the model context
  • Skill-based — agents discover capabilities through installable skills rather than verbose help text
  • Daemon architecture — persistent browser process means no startup cost per command
  • Ref-based — accessibility snapshots with element refs for deterministic interaction
  • Cross-browser — Chrome, Firefox, WebKit, and Edge support
  • Sessions — multiple isolated browser instances with separate state

Playwright CLI vs MCP​

Playwright CLIMCP
Best forCoding agents (Claude Code, Copilot) working with large codebasesSpecialized agentic loops, exploratory automation
How it worksAgent runs shell commandsLLM calls MCP tools with structured parameters
Token costLower — concise CLI output, skills loaded on demandHigher — tool schemas + snapshots in context
Default modeHeadlessHeaded
Setupnpm install -g @playwright/cliJSON config in MCP client

All Commands​

Run playwright-cli --help for the built-in listing, or playwright-cli --help <command> for a single command's arguments and options.

Core​

open [url] attach [name] close
detach goto <url> type <text>
click <target> [button] dblclick <target> [button] fill <target> <text>
drag <start> <end> drop <target> hover <target>
select <target> <val> upload <files...> check <target>
uncheck <target> snapshot [target] find [text]
eval <func> [target] dialog-accept [prompt] dialog-dismiss
resize <w> <h> delete-data
go-back go-forward reload

Keyboard​

press <key> keydown <key> keyup <key>

Mouse​

mousemove <x> <y> mousedown [button] mouseup [button]
mousewheel <dx> <dy>

Save as​

screenshot [target] pdf

Tabs​

tab-list tab-new [url] tab-close [index]
tab-select <index>

Storage​

state-load <file> state-save [file]
cookie-list cookie-get <name> cookie-set <name> <val>
cookie-delete <name> cookie-clear
localstorage-list localstorage-get <key> localstorage-set <k> <v>
localstorage-delete <key> localstorage-clear
sessionstorage-list sessionstorage-get <key> sessionstorage-set <k> <v>
sessionstorage-delete <k> sessionstorage-clear

Network​

requests request <index> request-headers <index>
request-body <index> response-headers <index> response-body <index>
route <pattern> route-list unroute [pattern]
network-state-set <state>

DevTools​

console [min-level] run-code [code] recording-start
recording-stop tracing-start tracing-stop
video-start [file] video-stop video-chapter <title>
video-show-actions video-hide-actions show
pause-at <location> resume step-over
generate-locator <target> highlight [target]

Install​

install install-browser [browser]

Browser sessions​

-s=<name> <cmd> list close-all
kill-all

Global options​

--help [command] --json --raw
--version