SKILL.md--- name: playwright-skill description: Complete browser automation with Playwright. Auto-detects dev servers, writes reusable test scripts, and supports screenshots, responsive checks, UX validation, login flows, link checks, and arbitrary browser automation. Use when the user wants to test a website, automate browser interactions, validate web functionality, or perform browser-based testing. license: MIT compatibility: Requires Node.js 20+, npm, and network access on first setup to install Playwright and Chromium. metadata: author: lackeyjb version: "5.0.0" allowed-tools: Bash(node:*) Bash(npm:*) Read Write --- # Playwright Browser Automation Write and execute focused Playwright scripts for the user's request. Prefer the skill's executor and helpers, but use the full Playwright API when needed. ## Path resolution This skill can be installed in several locations, so resolve its directory first. Set `SKILL_DIR` to the directory containing this SKILL.md file, then run the commands below as written: ```bash export SKILL_DIR=<absolute path of the directory containing this SKILL.md> export TMP_DIR="$(node -p 'require("node:os").tmpdir()')" ``` If shell state does not persist between commands, substitute the literal paths for `$SKILL_DIR` and `$TMP_DIR` in each command instead. Common installation paths: - Plugin system: `~/.claude/plugins/marketplaces/playwright-skill/skills/playwright-skill` - Manual global: `~/.claude/skills/playwright-skill` - Project-specific: `<project>/.claude/skills/playwright-skill` ## Workflow 1. For localhost work, detect running servers before writing a URL: ```bash node -e "require('$SKILL_DIR/lib/helpers').detectDevServers().then(s => console.log(JSON.stringify(s)))" ``` Use the only result automatically. Ask which URL to use when there are multiple results. Ask for a URL or offer to start a server when none exist. 2. Write reusable scripts to `$TMP_DIR/playwright-test-*.js` unless the user asks to save them in the project. Use `PW_SCRIPT_DIR` to preserve scripts. 3. Use a visible browser by default. Use `headless: true` only when requested or when the environment has no display. 4. Put the target URL in a constant or environment variable. 5. Run scripts with `node "$SKILL_DIR/run.js" <script.js>`. 6. Report actions, failures, and artifact paths. Do not claim success without checking the resulting page. ## Setup Run once: ```bash cd "$SKILL_DIR" && npm run setup ``` This installs Playwright and Chromium. Use `cd "$SKILL_DIR" && npm run install-all-browsers` when Firefox or WebKit is required. ## Minimal example ```javascript const os = require('node:os'); const path = require('node:path'); const { chromium } = require('playwright'); const targetUrl = process.env.TARGET_URL || 'http://localhost:3000'; const artifactDir = process.env.PW_ARTIFACT_DIR || os.tmpdir(); (async () => { const browser = await chromium.launch({ headl