Skip to main content

Coding agents

Introduction​

Playwright comes with playwright-cli, a command-line interface for browser automation designed for coding agents. It provides token-efficient browser control through concise CLI commands and installable skills, making it ideal for agents that need to balance browser automation with large codebases and reasoning within limited context windows.

playwright-cli vs Playwright MCP​

  • playwright-cli is best for coding agents (Claude Code, GitHub Copilot, etc.) that favor token-efficient, skill-based workflows. CLI commands avoid loading large tool schemas and verbose accessibility trees into the model context.
  • MCP is best for specialized agentic loops that benefit from persistent state and iterative reasoning over page structure, such as exploratory automation or long-running autonomous workflows. See the MCP getting started guide.

Prerequisites​

Before you begin, make sure you have the following installed:

  • Node.js 20 or newer
  • A coding agent: Claude Code, GitHub Copilot, or similar

Installation​

Install playwright-cli globally:

npm install -g @playwright/cli@latest
playwright-cli --help

Alternatively, install @playwright/cli as a local dependency and use npx:

npm install -D @playwright/cli@latest
npx playwright cli --help

Installing skills​

Coding agents like Claude Code and GitHub Copilot can use locally installed skills for richer context about available commands:

playwright-cli install --skills

To share the skills across all your projects, add the -g flag to install them into your home directory (~/.claude/skills or, with --skills=agents, ~/.agents/skills):

playwright-cli install --skills -g

Skills-less operation​

You can also point your agent at the CLI directly and let it discover commands on its own:

Test the "add todo" flow on https://demo.playwright.dev/todomvc using playwright-cli.
Check playwright-cli --help for available commands.

First Steps​

Interactive demo​

Try asking your coding agent:

Use playwright skills to test https://demo.playwright.dev/todomvc/.
Take screenshots for all successful and failing scenarios.

Manual walkthrough​

You can also run commands manually to see how the CLI works:

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 a snapshot of 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)

Core Commands​

Interacting with pages​

playwright-cli open [url] # open browser, optionally navigate to url
playwright-cli goto <url> # navigate to a url
playwright-cli click <ref> [button] # click an element
playwright-cli type <text> # type text into editable element
playwright-cli fill <ref> <text> # fill text into editable element
playwright-cli select <ref> <value> # select an option in a dropdown
playwright-cli check <ref> # check a checkbox or radio button
playwright-cli uncheck <ref> # uncheck a checkbox
playwright-cli hover <ref> # hover over element
playwright-cli drag <startRef> <endRef> # drag and drop between elements
playwright-cli upload <files...> # upload one or multiple files
playwright-cli close # close the page

Targeting elements​

Use element refs from snapshots to target elements:

playwright-cli snapshot # get snapshot with element refs
playwright-cli click e15 # click using a ref

You can also use CSS or role selectors:

playwright-cli click "#main > button.submit"
playwright-cli click "role=button[name=Submit]"
playwright-cli click "#footer >> role=button[name=Submit]"

Screenshots and snapshots​

playwright-cli snapshot # capture page snapshot
playwright-cli snapshot --filename=f # save snapshot to specific file
playwright-cli screenshot # screenshot of the current page
playwright-cli screenshot [ref] # screenshot of a specific element
playwright-cli screenshot --filename=f # save with specific filename
playwright-cli screenshot --hires # capture using device pixels
playwright-cli pdf # save page as PDF
playwright-cli go-back # go back
playwright-cli go-forward # go forward
playwright-cli reload # reload the page

Keyboard and mouse​

playwright-cli press <key> # press a key (e.g. Enter, ArrowLeft)
playwright-cli keydown <key> # key down
playwright-cli keyup <key> # key up
playwright-cli mousemove <x> <y> # move mouse
playwright-cli mousedown [button] # mouse button down
playwright-cli mouseup [button] # mouse button up
playwright-cli mousewheel <dx> <dy> # scroll

Tabs​

playwright-cli tab-list # list all tabs
playwright-cli tab-new [url] # create a new tab
playwright-cli tab-select <index> # select a tab
playwright-cli tab-close [index] # close a tab

Network​

playwright-cli requests # list network requests since page load
playwright-cli request <num> # show full details of a single request
playwright-cli route <pattern> [opts] # mock network requests
playwright-cli route-list # list active routes
playwright-cli unroute [pattern] # remove routes

Storage​

playwright-cli state-save [filename] # save storage state (cookies, localStorage)
playwright-cli state-load <filename> # load storage state