| name | playwright-cli |
| description | Playwright CLI for browser automation, code generation, screenshots, tracing, and test running via npx playwright |
Playwright CLI
There are two distinct tools — use the right one for the job:
| Tool | Binary | Best for |
|---|
playwright-cli | ~/.local/share/mise/installs/node/25.3.0/bin/playwright-cli | Live browser automation, connecting to existing sessions, interactive CLI control |
npx playwright | via mise/npx | Test running, codegen recording, tracing, CI |
playwright-cli — Interactive CLI Automation
Activation Triggers
- Automating an existing logged-in browser session
- Clicking/filling forms without writing scripts
- Connecting to a running Brave/Chrome via CDP
- Any browser task that benefits from step-by-step CLI control
Connecting to Existing Brave Session (CDP)
Create a config file to point at the running Brave CDP endpoint:
{
"browser": {
"cdpEndpoint": "http://localhost:9222"
}
}
Then all playwright-cli commands talk to the live Brave session automatically. No scripts needed.
Alternatively use the env var: PLAYWRIGHT_MCP_CDP_ENDPOINT=http://localhost:9222 playwright-cli snapshot
Core Workflow: snapshot → click
playwright-cli snapshot
playwright-cli click e42
playwright-cli click 'text=Submit'
playwright-cli fill e7 "hello"
playwright-cli screenshot
playwright-cli go-back
playwright-cli goto https://...
playwright-cli eval "document.title"
playwright-cli run-code "<playwright code snippet>"
Always snapshot first — it returns element refs (e1, e2, ...) and page structure so you know exactly what to click without guessing selectors.
All Core Commands
playwright-cli open [url]
playwright-cli goto <url>
playwright-cli close
playwright-cli snapshot
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 <ref1> <ref2>
playwright-cli press <key>
playwright-cli keydown / keyup <key>
playwright-cli mousemove <x> <y>
playwright-cli mousewheel <dx> <dy>
playwright-cli eval <func> [ref]
playwright-cli run-code <code>
playwright-cli dialog-accept [text]
playwright-cli dialog-dismiss
playwright-cli resize <w> <h>
Tabs
playwright-cli tab-list
playwright-cli tab-new [url]
playwright-cli tab-select <index>
playwright-cli tab-close [index]
Sessions (Multiple Browsers)
playwright-cli -s=myapp open https://example.com
playwright-cli -s=myapp snapshot
playwright-cli list
playwright-cli close-all
playwright-cli kill-all
Use PLAYWRIGHT_CLI_SESSION=name env var to set session for all commands.
Visual Dashboard
playwright-cli show
Lets you watch and take over control from any running session.
Save / Screenshot
playwright-cli screenshot
playwright-cli screenshot --filename=out.png
playwright-cli screenshot e5
playwright-cli pdf --filename=page.pdf
Storage & State
playwright-cli state-save auth.json
playwright-cli state-load auth.json
playwright-cli cookie-list
playwright-cli cookie-set name value
playwright-cli localstorage-list
playwright-cli localstorage-set key val
Config File (playwright-cli.json)
Full config schema highlights:
{
"browser": {
"cdpEndpoint": "http://localhost:9222",
"browserName": "chromium",
"userDataDir": "/tmp/my-profile",
"launchOptions": { "headless": false }
},
"outputDir": "./playwright-output",
"outputMode": "file",
"timeouts": {
"action": 5000,
"navigation": 60000
}
}
npx playwright — Test Runner & Codegen
Activation Triggers
- Writing/running Playwright tests (
.spec.ts)
- Recording codegen scripts
- CI pipelines
- Trace viewer
Code Generation
npx playwright codegen https://example.com
npx playwright codegen --target=javascript -o actions.js https://example.com
npx playwright codegen --browser=firefox https://example.com
Screenshots & PDF
npx playwright screenshot --full-page https://example.com full.png
npx playwright pdf https://example.com output.pdf
Test Running
npx playwright test
npx playwright test tests/login.spec.ts
npx playwright test --project=chromium
npx playwright test --headed
npx playwright test --ui
npx playwright test --trace on
npx playwright show-report
Tracing
npx playwright show-trace trace.zip
Browser Installation
npx playwright install
npx playwright install chromium
npx playwright install --with-deps chromium
Connecting to Existing Brave Session (Node.js scripts)
When you need full Playwright API control in a script (e.g., loops, complex logic):
const { chromium } = require('playwright');
const browser = await chromium.connectOverCDP('http://localhost:9222');
const context = browser.contexts()[0];
const page = context.pages()[0];
await browser.close();
Note: playwright is not globally installed. Either:
- Run from
/tmp/play_test/ (has it installed)
- Or use
playwright-cli with CDP config instead — no scripting needed
Best Practices
- Prefer
playwright-cli + CDP config over writing Node.js scripts for live session automation — it's faster and requires no boilerplate
- Always
snapshot before clicking — gets accurate element refs, avoids selector guessing
- Use
playwright-cli show to visually monitor what the automation is doing
- Use
npx playwright codegen to bootstrap test scripts, then refine manually
- Use
--trace on during test development for failure debugging
Related Skills
- brave: Launch Brave (Flatpak) with remote debugging for CDP connection (
--remote-debugging-port=9222)