Playwright-Efficient Web Research
Use this skill for web exploration tasks where context window efficiency matters.
Use This Skill When
- The user asks to research web pages, compare content across sites, or extract specific facts.
- Browser interaction is required (click, type, login flow, pagination, dynamic content).
- Repeated full HTML/text fetch would waste tokens.
CLI vs MCP Boundary
- Default: Playwright CLI (
playwright-cli) with direct commands (no wrapper scripts). - Fallback: Playwright MCP only for long-running/state-heavy autonomous loops requiring persistent tool-level introspection.
Core Rules
- Reuse one named session per task (
-s=<session>); avoid reopening browser every step. - In this sandbox, pass
--browser=chromiumexplicitly unless you intentionally need another channel. - Use
snapshotto get element refs, then interact by ref (click e12,fill e8 ...). - Extract only required fields with
eval; do not dump full page content unless explicitly requested. - Capture screenshot/PDF/logs only when evidence is required.
- Close session when done (
close, optionaldelete-data). - Keep sessions non-persistent by default; enable
--persistentonly when cross-command login state is explicitly required.
Workflow (Direct CLI)
- Open session once (default: non-persistent):
playwright-cli -s=research-1 open "https://example.com" --browser=chromium
If the workflow explicitly requires saved login/session state:
playwright-cli -s=research-1 open "https://example.com" --browser=chromium --persistent
- Navigate + interact with refs:
playwright-cli -s=research-1 snapshot
playwright-cli -s=research-1 click e15
playwright-cli -s=research-1 fill e7 "search query"
playwright-cli -s=research-1 press Enter
- Targeted extraction (minimum needed fields only):
playwright-cli -s=research-1 eval \
"() => ({ title: document.title, h1: document.querySelector('h1')?.textContent?.trim() ?? null })"
playwright-cli -s=research-1 eval "el => el.textContent?.trim() ?? null" e15
- Optional evidence:
playwright-cli -s=research-1 screenshot --filename=/tmp/research-1.png
playwright-cli -s=research-1 pdf --filename=/tmp/research-1.pdf
playwright-cli -s=research-1 console
playwright-cli -s=research-1 network
- Cleanup:
playwright-cli -s=research-1 close
playwright-cli -s=research-1 delete-data
Anti-Patterns
- Repeatedly opening new sessions for each click.
- Fetching complete page text/DOM when only 2-3 fields are needed.
- Using screenshots as default extraction path.
- Adding unnecessary wrapper scripts when direct CLI commands are sufficient.
- Switching to MCP for simple linear navigation tasks.
Notes
- If global
playwright-cliis unavailable, run the same commands withnpx --yes @playwright/cli .... - Session names should be task-specific (
news-compare,pricing-check,auth-flow-debug).
