$npx -y skills add appautomaton/webmaton --skill playwright-cliUse when a task needs Playwright-backed browser automation from the shell: open or attach to browser sessions, inspect snapshots and element refs, click/type/fill forms, debug Playwright tests, inspect console/network/storage, run Playwright snippets, capture screenshots/traces/v
| 1 | # playwright-cli |
| 2 | |
| 3 | `playwright-cli` is a token-efficient shell interface to Playwright. It keeps browser state across commands, exposes page snapshots with stable element refs such as `e15`, and prints the Playwright code it ran so the interaction can be converted into tests. |
| 4 | |
| 5 | ## Core Workflow |
| 6 | |
| 7 | ```bash |
| 8 | playwright-cli open https://example.com |
| 9 | playwright-cli snapshot |
| 10 | playwright-cli click e15 |
| 11 | playwright-cli fill e5 "user@example.com" |
| 12 | playwright-cli press Enter |
| 13 | playwright-cli close |
| 14 | ``` |
| 15 | |
| 16 | Use refs from the latest snapshot by default. Re-run `snapshot` after navigation, major DOM changes, or a failed ref action. Use CSS selectors or Playwright locators only when refs are unavailable or unstable. |
| 17 | |
| 18 | ## Operating Rules |
| 19 | |
| 20 | - Discover exact syntax with `playwright-cli --help` and `playwright-cli <command> --help`; the CLI changes quickly. |
| 21 | - Use `--raw` when piping values into other tools. Use `--json` only if the installed CLI advertises it. |
| 22 | - Use named sessions with `-s=<name>` for concurrent or long-lived work. |
| 23 | - Use `open --persistent` only when disk-persisted cookies/storage are needed. |
| 24 | - Prefer `attach --cdp=chrome`, `attach --cdp=msedge`, or `attach --cdp=http://127.0.0.1:9222` when the task needs an existing browser/session. |
| 25 | - Close sessions when finished. Reserve `close-all` and `kill-all` for cleanup of stale sessions. |
| 26 | |
| 27 | ## Common Tasks |
| 28 | |
| 29 | ```bash |
| 30 | playwright-cli open https://example.com --browser=chrome |
| 31 | playwright-cli snapshot --depth=4 |
| 32 | playwright-cli screenshot --filename=page.png |
| 33 | playwright-cli console warning |
| 34 | playwright-cli network --filter="/api/.*" --request-headers |
| 35 | playwright-cli run-code "async page => await page.context().grantPermissions(['geolocation'])" |
| 36 | playwright-cli tracing-start |
| 37 | playwright-cli tracing-stop |
| 38 | ``` |
| 39 | |
| 40 | For a broader command map, read `references/cli-reference.md`. |
| 41 | |
| 42 | ## Playwright Test Debugging |
| 43 | |
| 44 | When a Playwright test fails, prefer the CLI debug workflow: |
| 45 | |
| 46 | ```bash |
| 47 | PLAYWRIGHT_HTML_OPEN=never npx playwright test --debug=cli |
| 48 | # wait for "Debugging Instructions", then attach to the printed session |
| 49 | playwright-cli attach tw-abcdef |
| 50 | ``` |
| 51 | |
| 52 | Keep the test process running while inspecting the paused page. Use snapshots, console/network inspection, and generated Playwright code to identify the fix. |
| 53 | |
| 54 | ## References |
| 55 | |
| 56 | Load only what the task needs: |
| 57 | |
| 58 | - `references/cli-reference.md` — command groups, output modes, and version-sensitive features |
| 59 | - `references/playwright-tests.md` — running and debugging Playwright tests |
| 60 | - `references/request-mocking.md` — route mocking and request interception |
| 61 | - `references/running-code.md` — custom Playwright snippets with `run-code` |
| 62 | - `references/session-management.md` — named sessions and cleanup |
| 63 | - `references/storage-state.md` — cookies, localStorage, sessionStorage, auth state |
| 64 | - `references/test-generation.md` — turning CLI output into tests |
| 65 | - `references/tracing.md` — trace capture and inspection |
| 66 | - `references/video-recording.md` — WebM recording and chapter markers |
| 67 | - `references/element-attributes.md` — inspect IDs/classes/data attributes not shown in snapshots |