| name | playwright-cli |
| description | Automate browser interactions for web testing, form filling, screenshots, and data extraction using playwright-cli. Use when the user needs to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, scrape data, or extract information from web pages. Triggers on "ブラウザ操作", "Webテスト", "スクリーンショット", "フォーム入力", "スクレイピング", "browser automation", "web testing", "playwright". |
Browser Automation with playwright-cli
Prerequisites
Before running any playwright-cli command, verify installation:
which playwright-cli || npm install -g @playwright/cli@latest
If the global install fails, fall back to npx playwright-cli for all commands.
Quick Start
playwright-cli open https://example.com
playwright-cli snapshot
playwright-cli click e15
playwright-cli fill e5 "user@example.com"
playwright-cli screenshot
playwright-cli close
Core Commands
playwright-cli open [url]
playwright-cli goto <url>
playwright-cli go-back / go-forward / reload
playwright-cli click <ref>
playwright-cli dblclick <ref>
playwright-cli fill <ref> "<value>"
playwright-cli type "<text>"
playwright-cli select <ref> "<option-value>"
playwright-cli check / uncheck <ref>
playwright-cli hover <ref>
playwright-cli drag <ref-from> <ref-to>
playwright-cli upload <file-path>
playwright-cli press Enter|ArrowDown|Tab|...
playwright-cli keydown / keyup Shift
playwright-cli mousemove <x> <y>
playwright-cli mousedown / mouseup [right]
playwright-cli mousewheel <dx> <dy>
playwright-cli snapshot [--filename=name.yaml]
playwright-cli screenshot [ref] [--filename=page.png]
playwright-cli pdf [--filename=page.pdf]
playwright-cli eval "<js-expression>" [ref]
playwright-cli dialog-accept ["text"]
playwright-cli dialog-dismiss
playwright-cli resize <width> <height>
playwright-cli tab-list / tab-new [url] / tab-select <index> / tab-close [index]
playwright-cli -s=<name> <command>
playwright-cli list
playwright-cli close / close-all / kill-all
Snapshots
After each command, playwright-cli outputs a snapshot with element refs (e1, e2, etc.). Use these refs to interact with elements.
Named Sessions
Use -s=<name> for isolated browser sessions with independent cookies/storage:
playwright-cli -s=auth open https://app.example.com/login
playwright-cli -s=public open https://example.com
Open Parameters
playwright-cli open --browser=chrome|firefox|webkit|msedge
playwright-cli open --persistent
playwright-cli open --profile=/path/to/dir
playwright-cli open --config=config.json
playwright-cli open --extension
Storage Commands
playwright-cli state-save [filename.json]
playwright-cli state-load <filename.json>
playwright-cli cookie-list [--domain=example.com]
playwright-cli cookie-get / cookie-set / cookie-delete <name>
playwright-cli cookie-clear
playwright-cli localstorage-list / localstorage-get / localstorage-set / localstorage-delete <key>
playwright-cli localstorage-clear
playwright-cli sessionstorage-list / sessionstorage-get / sessionstorage-set / sessionstorage-delete <key>
playwright-cli sessionstorage-clear
DevTools
playwright-cli console [warning]
playwright-cli network
playwright-cli run-code "async page => { /* Playwright code */ }"
playwright-cli tracing-start / tracing-stop
playwright-cli video-start / video-stop <output.webm>
Network Mocking
playwright-cli route "**/*.jpg" --status=404
playwright-cli route "**/api/users" --body='[{"id":1}]' --content-type=application/json
playwright-cli route-list
playwright-cli unroute ["pattern"]
Specific Tasks (Reference Files)
Read the relevant reference file for detailed guides:
- Request mocking —
references/request-mocking.md
- Running custom Playwright code —
references/running-code.md
- Browser session management —
references/session-management.md
- Storage state (cookies, localStorage) —
references/storage-state.md
- Test generation —
references/test-generation.md
- Tracing —
references/tracing.md
- Video recording —
references/video-recording.md
Common Workflow: Form Submission
playwright-cli open https://example.com/form
playwright-cli snapshot
playwright-cli fill e1 "user@example.com"
playwright-cli fill e2 "password123"
playwright-cli click e3
playwright-cli snapshot
playwright-cli close
Common Workflow: Auth State Reuse
playwright-cli open https://app.example.com/login
playwright-cli fill e1 "user@example.com"
playwright-cli fill e2 "secret"
playwright-cli click e3
playwright-cli state-save auth.json
playwright-cli close
playwright-cli state-load auth.json
playwright-cli open https://app.example.com/dashboard