Use when the task requires automating a real browser from the terminal (navigation, form filling, snapshots, screenshots, data extraction, UI-flow debugging) via `playwright-cli` or the bundled wrapper script.
Add this skill
npx mdskills install openai/playwrightClear CLI-first browser automation with prerequisite checks, workflow patterns, and sensible guardrails
1---2name: "playwright"3description: "Use when the task requires automating a real browser from the terminal (navigation, form filling, snapshots, screenshots, data extraction, UI-flow debugging) via `playwright-cli` or the bundled wrapper script."4---567# Playwright CLI Skill89Drive a real browser from the terminal using `playwright-cli`. Prefer the bundled wrapper script so the CLI works even when it is not globally installed.10Treat this skill as CLI-first automation. Do not pivot to `@playwright/test` unless the user explicitly asks for test files.1112## Prerequisite check (required)1314Before proposing commands, check whether `npx` is available (the wrapper depends on it):1516```bash17command -v npx >/dev/null 2>&118```1920If it is not available, pause and ask the user to install Node.js/npm (which provides `npx`). Provide these steps verbatim:2122```bash23# Verify Node/npm are installed24node --version25npm --version2627# If missing, install Node.js/npm, then:28npm install -g @playwright/cli@latest29playwright-cli --help30```3132Once `npx` is present, proceed with the wrapper script. A global install of `playwright-cli` is optional.3334## Skill path (set once)3536```bash37export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"38export PWCLI="$CODEX_HOME/skills/playwright/scripts/playwright_cli.sh"39```4041User-scoped skills install under `$CODEX_HOME/skills` (default: `~/.codex/skills`).4243## Quick start4445Use the wrapper script:4647```bash48"$PWCLI" open https://playwright.dev --headed49"$PWCLI" snapshot50"$PWCLI" click e1551"$PWCLI" type "Playwright"52"$PWCLI" press Enter53"$PWCLI" screenshot54```5556If the user prefers a global install, this is also valid:5758```bash59npm install -g @playwright/cli@latest60playwright-cli --help61```6263## Core workflow64651. Open the page.662. Snapshot to get stable element refs.673. Interact using refs from the latest snapshot.684. Re-snapshot after navigation or significant DOM changes.695. Capture artifacts (screenshot, pdf, traces) when useful.7071Minimal loop:7273```bash74"$PWCLI" open https://example.com75"$PWCLI" snapshot76"$PWCLI" click e377"$PWCLI" snapshot78```7980## When to snapshot again8182Snapshot again after:8384- navigation85- clicking elements that change the UI substantially86- opening/closing modals or menus87- tab switches8889Refs can go stale. When a command fails due to a missing ref, snapshot again.9091## Recommended patterns9293### Form fill and submit9495```bash96"$PWCLI" open https://example.com/form97"$PWCLI" snapshot98"$PWCLI" fill e1 "user@example.com"99"$PWCLI" fill e2 "password123"100"$PWCLI" click e3101"$PWCLI" snapshot102```103104### Debug a UI flow with traces105106```bash107"$PWCLI" open https://example.com --headed108"$PWCLI" tracing-start109# ...interactions...110"$PWCLI" tracing-stop111```112113### Multi-tab work114115```bash116"$PWCLI" tab-new https://example.com117"$PWCLI" tab-list118"$PWCLI" tab-select 0119"$PWCLI" snapshot120```121122## Wrapper script123124The wrapper script uses `npx --package @playwright/cli playwright-cli` so the CLI can run without a global install:125126```bash127"$PWCLI" --help128```129130Prefer the wrapper unless the repository already standardizes on a global install.131132## References133134Open only what you need:135136- CLI command reference: `references/cli.md`137- Practical workflows and troubleshooting: `references/workflows.md`138139## Guardrails140141- Always snapshot before referencing element ids like `e12`.142- Re-snapshot when refs seem stale.143- Prefer explicit commands over `eval` and `run-code` unless needed.144- When you do not have a fresh snapshot, use placeholder refs like `eX` and say why; do not bypass refs with `run-code`.145- Use `--headed` when a visual check will help.146- When capturing artifacts in this repo, use `output/playwright/` and avoid introducing new top-level artifact folders.147- Default to CLI commands and workflows, not Playwright test specs.148
Full transparency — inspect the skill content before installing.