playwright

Playwright CLI recipes for E2E testing, screenshots, PDF export, and accessibility audits. Use instead of browser MCP tools for deterministic, token-efficient browser automation.

5 stars

Best use case

playwright is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Playwright CLI recipes for E2E testing, screenshots, PDF export, and accessibility audits. Use instead of browser MCP tools for deterministic, token-efficient browser automation.

Teams using playwright should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/playwright/SKILL.md --create-dirs "https://raw.githubusercontent.com/vamseeachanta/workspace-hub/main/.agents/skills/workspace-hub/playwright/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/playwright/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How playwright Compares

Feature / AgentplaywrightStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Playwright CLI recipes for E2E testing, screenshots, PDF export, and accessibility audits. Use instead of browser MCP tools for deterministic, token-efficient browser automation.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Playwright CLI Skill

> Token-efficient browser automation via `npx playwright` CLI.
> Prefer this over MCP browser tools for deterministic, scriptable tasks.

## Quick Start

```bash
# Install (one-time) — only chromium needed for most tasks
npx playwright install chromium
```

## Decision Matrix: Playwright CLI vs Chrome MCP

| Use Case | Tool | Why |
|----------|------|-----|
| Page screenshot | Playwright CLI | Single command, ~27K tokens vs ~114K MCP |
| PDF export | Playwright CLI | Native `npx playwright pdf` command |
| E2E test suite | Playwright CLI | `npx playwright test` with config file |
| Accessibility audit | Playwright CLI | Scriptable, repeatable, CI-friendly |
| UI visual audit | Playwright CLI | gsd-ui-auditor already uses this pattern |
| Interactive exploration | Chrome MCP | Stateful browsing, clicking, form filling |
| Live debugging | Chrome MCP | Real-time DOM inspection, console access |
| Multi-step navigation | Chrome MCP | When path is unknown, needs human-like exploration |

**Rule of thumb:** If the task is scriptable and deterministic, use Playwright CLI.
If the task requires interactive exploration or unknown navigation, use Chrome MCP.

## Recipes

### 1. Page Screenshot

```bash
# Basic screenshot
npx playwright screenshot <url> <output.png>

# Full-page (scrollable area)
npx playwright screenshot --full-page <url> <output.png>

# Mobile viewport
npx playwright screenshot --device "iPhone 12" <url> <output-mobile.png>

# Dark mode
npx playwright screenshot --color-scheme dark <url> <output-dark.png>

# Wait for dynamic content
npx playwright screenshot --wait-for-selector ".loaded" <url> <output.png>
npx playwright screenshot --wait-for-timeout 3000 <url> <output.png>

# Multi-viewport capture (desktop + mobile + tablet)
npx playwright screenshot --full-page <url> desktop.png
npx playwright screenshot --device "iPhone 12" <url> mobile.png
npx playwright screenshot --device "iPad Pro 11" <url> tablet.png
```

### 2. PDF Export

```bash
# Default (Letter size)
npx playwright pdf <url> <output.pdf>

# A4 format
npx playwright pdf --paper-format A4 <url> <output.pdf>

# Wait for content before export
npx playwright pdf --wait-for-selector ".content-loaded" <url> <output.pdf>
```

### 3. E2E Test Runner

```bash
# Run all tests
npx playwright test

# Run specific test file
npx playwright test tests/e2e/login.spec.ts

# Run with specific browser
npx playwright test --project=chromium

# Run in headed mode (for debugging)
npx playwright test --headed

# Run with HTML report
npx playwright test --reporter=html

# Run single test by title
npx playwright test -g "should display dashboard"

# Debug mode (step through)
npx playwright test --debug
```

### 4. Accessibility Audit

```python
# accessibility-audit.py — run with: python accessibility-audit.py <url>
import sys, json
from playwright.sync_api import sync_playwright

url = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:3000"

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    page = browser.new_page()
    page.goto(url)

    # Snapshot accessibility tree
    snapshot = page.accessibility.snapshot()
    print(json.dumps(snapshot, indent=2))

    # Check for missing alt text
    images = page.query_selector_all("img:not([alt])")
    if images:
        print(f"\nWARNING: {len(images)} images missing alt text")

    # Check for missing form labels
    inputs = page.query_selector_all("input:not([aria-label]):not([id])")
    if inputs:
        print(f"WARNING: {len(inputs)} inputs missing labels")

    browser.close()
```

### 5. Code Generation (Record and Replay)

```bash
# Record user actions and generate test code
npx playwright codegen <url>

# Generate code for specific browser
npx playwright codegen --browser firefox <url>

# Generate code targeting specific language
npx playwright codegen --target python <url>
```

## Token Cost Context

Playwright CLI uses ~4x fewer tokens than MCP-based browser tools for equivalent tasks:
- **CLI screenshot:** ~27K tokens (single shell command + file path result)
- **MCP screenshot:** ~114K tokens (tool schemas loaded, browser state in context, JSON roundtrips)
- **CLI test run:** compact stdout output, results on disk
- **MCP test equivalent:** full DOM state serialized into context window each step

The savings compound over longer sessions. CLI keeps browser state on disk; MCP keeps it in the model's context window.

## Integration with Existing Tools

- **gsd-ui-auditor** already uses `npx playwright screenshot` for multi-viewport captures
- **webapp-testing skill** provides Python-based Playwright patterns for deeper integration
- **tests/playwright.config.js** defines the project's E2E test configuration

## Common Options (All Commands)

| Flag | Description |
|------|-------------|
| `-b, --browser <type>` | `cr`, `ff`, `wk` (default: `chromium`) |
| `--device <name>` | Emulate device (e.g., `"iPhone 12"`, `"iPad Pro 11"`) |
| `--color-scheme <scheme>` | `light` or `dark` |
| `--ignore-https-errors` | Skip certificate validation |
| `--load-storage <file>` | Load auth state from file |
| `--lang <locale>` | Set language (e.g., `en-GB`) |
| `--proxy-server <url>` | Route through proxy |
| `--wait-for-selector <sel>` | Wait for element before action |
| `--wait-for-timeout <ms>` | Wait N milliseconds before action |

Related Skills

test-oversized-skill

5
from vamseeachanta/workspace-hub

A test fixture skill that exceeds 200 lines with multiple H2/H3 sections for split testing.

interactive-report-generator

5
from vamseeachanta/workspace-hub

Generate interactive HTML reports with Plotly visualizations from data analysis results. Supports dashboards, charts, and professional styling.

data-validation-reporter

5
from vamseeachanta/workspace-hub

Generate interactive validation reports with quality scoring, missing data analysis, and type checking. Combines Pandas validation, Plotly visualization, and YAML configuration for comprehensive data quality reporting.

agent-os-framework

5
from vamseeachanta/workspace-hub

Generate standardized .agent-os directory structure with product documentation, mission, tech-stack, roadmap, and decision records. Enables AI-native workflows.

OrcaFlex Specialist Skill

5
from vamseeachanta/workspace-hub

```yaml

repo-ecosystem-hygiene

5
from vamseeachanta/workspace-hub

Interpret the daily read-only repo ecosystem hygiene audit and route remediation through approved workflows.

domain-knowledge-sweep

5
from vamseeachanta/workspace-hub

Systematic multi-source research of an engineering domain. Spawns parent issue → 6 research subissues (Standards, Academic, Industry, LinkedIn-marketing, Code-audit, Synthesis) → gap implementation subissues. Replaces LinkedIn-only extraction with defensible comprehensive sourcing.

subagent-write-verification

5
from vamseeachanta/workspace-hub

Independently verify subagent-claimed file writes with filesystem and git checks before treating the artifact as real, before committing it, and before referencing the path in downstream prompts.

git-operation-serialization-preflight

5
from vamseeachanta/workspace-hub

Before any commit, stash, merge, reset, rebase, or checkout in a multi-agent or shared-checkout environment, run a bounded preflight to detect active git writers and stale index/config locks, then serialize the mutating step under a single-writer guarantee.

public-knowledge-graph-governance

5
from vamseeachanta/workspace-hub

Maintain public-safe knowledge graph artifacts for llm-wiki and similar markdown knowledge bases. Use when changing graph generators, validators, schema docs, weekly freshness checks, or public/private source-scope boundaries.

llm-wiki-weekly-freshness

5
from vamseeachanta/workspace-hub

Class-level governance workflow for keeping llm-wiki-style markdown knowledge bases current, public-safe, graph/index-valid, and useful for code development. Use when reviewing llm-wiki architecture/content, scanning new LLM concepts, maintaining public knowledge graphs, producing an issue roadmap, or running recurring freshness cadence.

llm-wiki-source-extraction-coverage

5
from vamseeachanta/workspace-hub

Doc-type-aware extraction contract for llm-wiki source ingestion with measurable coverage and source-anchored traceability. Use when (1) ingesting a PDF, DOCX, XLSX, PPTX, HTML, or scanned-image source into a wiki `sources/` page, (2) computing the pre-extraction estimate (what fraction of the source we expect to recover) and post-extraction yield (what fraction we actually recovered), (3) anchoring wiki claims back to specific page / paragraph / cell / slide positions in the source so a reviewer can re-verify or revise against the actual document, (4) deciding whether OCR fallback or manual transcription is needed. Codifies workspace-hub's existing OCR fallback chain and python-docx / openpyxl / trafilatura patterns into a format-specific routing table. Companion to research/llm-wiki-page-shape-contract (Rule 7 input-layer pages) and research/llm-wiki — this skill is the defense against silent extraction failure.