| created | "2026-03-19T00:00:00.000Z" |
| modified | "2026-03-19T00:00:00.000Z" |
| reviewed | "2026-03-19T00:00:00.000Z" |
| name | playwright-cli |
| description | Playwright CLI browser automation — navigate, screenshot, fill forms, click. Use when automating browser tasks from the shell; 4-10x more token-efficient than Playwright MCP. |
| user-invocable | false |
| allowed-tools | Bash, Read, Grep, Glob, TodoWrite |
Playwright CLI
Playwright CLI (@playwright/cli) is a terminal-first browser automation tool designed for AI coding agents. It provides shell commands for browser control, saving snapshots and screenshots to disk instead of injecting them into the LLM context window.
When to Use This Skill
| Use this skill when... | Use another skill instead when... |
|---|
| Automating browser tasks from CLI | Writing E2E test suites (use playwright-testing) |
| Navigating pages, clicking, filling forms | Sandboxed env without shell access (use Playwright MCP) |
| Taking screenshots or PDFs of web pages | Testing across multiple browsers systematically (use playwright-testing) |
| Verifying UI state during development | Setting up testing infrastructure (use configure-ux-testing) |
| Scraping or inspecting page content | Short exploratory sessions needing rich DOM inspection (use MCP) |
CLI vs MCP
| Factor | Playwright CLI | Playwright MCP |
|---|
| Token cost per task | ~27K tokens | ~114K tokens |
| Schema overhead | ~68 tokens (SKILL.md) | ~3,600 tokens (26 tools) |
| Requires | Shell/Bash access | MCP server config |
| Output | Files on disk | Inline in context |
| Best for | AI agents with shell (Claude Code, Copilot) | Sandboxed envs (Claude Desktop, Cursor) |
Rule of thumb: If the agent has Bash access, use CLI. If not, use MCP.
Installation
npm install -g @playwright/cli@latest
npm install --save-dev @playwright/cli@latest
playwright-cli --version
npx playwright-cli --version
Creates a .playwright-cli/ directory in the workspace for sessions, snapshots, and screenshots.
Core Workflow
The typical agent loop is: snapshot → find ref → interact → snapshot again.
playwright-cli goto https://example.com
playwright-cli snapshot
cat .playwright-cli/snapshot.yaml
playwright-cli click e21
playwright-cli fill e35 "user@example.com"
playwright-cli snapshot
Essential Commands
Navigation
playwright-cli open [url]
playwright-cli goto <url>
playwright-cli go-back
playwright-cli go-forward
playwright-cli reload
playwright-cli close
Interaction (using element refs from snapshots)
playwright-cli click <ref>
playwright-cli dblclick <ref>
playwright-cli fill <ref> <text>
playwright-cli type <text>
playwright-cli hover <ref>
playwright-cli select <ref> <val>
playwright-cli check <ref>
playwright-cli uncheck <ref>
playwright-cli drag <start> <end>
playwright-cli upload <file>
Keyboard & Mouse
playwright-cli press Enter
playwright-cli press Tab
playwright-cli keydown Shift
playwright-cli keyup Shift
playwright-cli mousemove 150 300
Snapshots & Screenshots
playwright-cli snapshot
playwright-cli snapshot --filename=login.yaml
playwright-cli screenshot
playwright-cli pdf output.pdf
Session Management
playwright-cli -s=myapp goto https://app.com
playwright-cli -s=myapp snapshot
playwright-cli list
playwright-cli -s=myapp close
playwright-cli close-all
playwright-cli kill-all
Browser Options
playwright-cli open --headed
playwright-cli open --persistent
playwright-cli -s=name delete-data
Common Patterns
Form Submission
playwright-cli goto https://app.com/login
playwright-cli snapshot
playwright-cli fill e12 "user@example.com"
playwright-cli fill e15 "password123"
playwright-cli click e18
playwright-cli snapshot
Page Verification
playwright-cli goto https://app.com/dashboard
playwright-cli screenshot
playwright-cli snapshot
Multi-Tab Workflow
playwright-cli -s=tab1 goto https://docs.example.com
playwright-cli -s=tab2 goto https://app.example.com
playwright-cli -s=tab1 snapshot
playwright-cli -s=tab2 fill e5 "value from docs"
Agentic Optimizations
| Context | Command |
|---|
| Navigate and verify | playwright-cli goto <url> && playwright-cli snapshot |
| Quick visual check | playwright-cli goto <url> && playwright-cli screenshot |
| Fill form field | playwright-cli fill <ref> '<value>' |
| Click and snapshot | playwright-cli click <ref> && playwright-cli snapshot |
| Save page as PDF | playwright-cli goto <url> && playwright-cli pdf out.pdf |
| Persistent session | playwright-cli open --persistent && playwright-cli goto <url> |
| Named session | playwright-cli -s=name goto <url> |
| Clean up | playwright-cli close-all |
Output Behavior
| Command Type | Output |
|---|
| snapshot | YAML file saved to .playwright-cli/ |
| screenshot, pdf | File saved to .playwright-cli/ |
| click, fill, type | No output (modifies browser state) |
| list | Session list to stdout |
| goto, reload | No output (navigates) |
Snapshots and screenshots are saved to disk — the agent reads them only when needed, keeping token usage minimal.
See Also