/playwright:visual-difffrom playwright
Takes Playwright screenshots of a baseline and current URL at multiple breakpoints, runs pixel-level image diffs, and reports visual differences to guide CSS/HTML corrections.
Ships in playwright. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Compare two URLs visually — a baseline (e.g. production site) and a current (e.g. local dev server or Storybook story) — to find pixel-level differences and guide corrections.
Before starting, confirm:
.vscode/mcp.json with --caps=visionpackage.json devDependencies:4321, Storybook on :6006, etc.)temp/ directory exists in the workspace root (it's gitignored)If the dev server or Storybook isn't running, start them using the VS Code tasks:
The agent needs:
| Input | Required | Example |
|---|---|---|
| Baseline URL | Yes | https://www.bitovi.com/ |
| Current URL | Yes | http://localhost:4321/ or http://localhost:6006/?path=/story/card--default |
| CSS selector | No | #hero-section or .card-grid (for element-scoped comparison) |
| Breakpoints | No | Defaults to mobile (375×667), tablet (768×1024), desktop (1280×720) |
When comparing a specific component — especially when the Storybook story renders only that component but the baseline page has a full page around it — crop to the component's bounding box so the diff isn't polluted by unrelated page sections (nav bars, sticky overlays, other modules above/below).
How to crop on the baseline page:
{ width: 1280, height: 720 }() => document.querySelector('<selector>').scrollIntoView({ behavior: 'instant', block: 'start' })
() => document.querySelector('<selector>').getBoundingClientRect().height
mcp_playwright_browser_resize → { width: 1280, height: <measured height> }
Background bleed warning: What's visible behind the component will differ between Storybook (blank) and the baseline page (other modules). Common cases: sticky/local nav bars overlapping the top, modals/overlays with other page content visible behind them, and partially transparent components. These residual diffs cluster outside the component's own content and are not actionable — ignore them.
How to crop on the Storybook story:
Storybook iframe.html renders only the component with no surrounding chrome — no resizing needed. Just navigate and screenshot:
mcp_playwright_browser_navigate → { url: "http://localhost:6006/iframe.html?id=<story-id>&viewMode=story" }
mcp_playwright_browser_resize → { width: 1280, height: <same height as baseline crop> }
mcp_playwright_browser_take_screenshot → { filename: "temp/vdiff-current-desktop.png" }
1. mcp_playwright_browser_navigate → { url: "<baseline-url>" }
2. mcp_playwright_browser_resize → { width: 1280, height: 720 }
3. mcp_playwright_browser_wait_for → { time: 2 } # let page fully render
4. mcp_playwright_browser_take_screenshot → {
type: "png",
filename: "temp/vdiff-baseline-desktop.png"
}
Repeat for each breakpoint:
| Breakpoint | Width | Height | Filename suffix |
|---|---|---|---|
| Mobile | 375 | 667 | -mobile |
| Tablet | 768 | 1024 | -tablet |
| Desktop | 1280 | 720 | -desktop |
Repeat the exact same process for the current URL, using temp/vdiff-current-{breakpoint}.png filenames.
Important: Use the same viewport dimensions and the same cropping strategy (component-scoped or full-page) on both sides so the comparison is apples-to-apples.
For each breakpoint, run the visual-diff script in the terminal:
node scripts/visual-diff.mjs \
--baseline temp/vdiff-baseline-desktop.png \
--current temp/vdiff-current-desktop.png \
--output temp/vdiff-diff-desktop.png
The script outputs JSON to stdout:
{
"totalPixels": 921600,
"diffPixels": 4521,
"diffPercent": 0.49,
"width": 1280,
"height": 720,
"baselineDimensions": { "width": 1280, "height": 720 },
"currentDimensions": { "width": 1280, "height": 720 },
"dimensionsMismatch": false,
"diffImagePath": "/absolute/path/to/temp/vdiff-diff-desktop.png"
}
If dimensionsMismatch is true, the images had different sizes. The script pads the smaller image with transparent pixels before comparing. This often indicates a layout issue worth investigating.
Start a temporary HTTP server to serve the temp/ directory, then navigate Playwright to the diff image:
# Start server in background (run once per session)
npx -y http-server temp/ -p 8787 --cors -c-1 &
Then navigate Playwright to the diff image:
mcp_playwright_browser_navigate → { url: "http://localhost:8787/vdiff-diff-desktop.png" }
mcp_playwright_browser_take_screenshot → {} # triggers vision — agent can now see the diff
The --caps=vision flag on Playwright MCP means the agent can see the image directly in the screenshot output.
Note: file:// URLs are blocked by Playwright MCP, so the HTTP server is required. Start it once and reuse it for all diff images in the session.
Reading the diff image:
Combine the quantitative JSON data with the visual diff inspection:
| diffPercent | Interpretation | Action |
|---|---|---|
| < 1% | Visually identical | Minor sub-pixel differences only. No action needed. |
| 1–5% | Close match | Inspect diff image for spacing, font weight, or border differences. Small CSS tweaks likely needed. |
| 5–15% | Notable differences | Layout shifts, color mismatches, or missing elements. Review the red clusters in the diff to identify which sections need work. |
| > 15% | Significant gap | Major structural or styling differences. Focus on the largest red regions first — these indicate the biggest layout discrepancies. |
When interpreting the diff image, note:
diffPercent reaches an acceptable levelTypical targets:
By default, screenshots capture only the visible viewport. For long pages, use the fullPage option:
mcp_playwright_browser_take_screenshot → {
type: "png",
fullPage: true,
filename: "temp/vdiff-baseline-desktop-full.png"
}
Warning: Full-page screenshots produce large images and slower diffs. Only use when comparing entire page layouts.
When screenshotting Storybook stories:
Use the iframe URL for cleaner screenshots (no Storybook chrome):
http://localhost:6006/iframe.html?id=components-card--default&viewMode=story
Wait for render — Storybook stories may take a moment to hydrate:
mcp_playwright_browser_wait_for → { time: 3 }
Element screenshots work well for isolating the story content from any Storybook padding.
The --threshold flag (0 to 1) controls pixelmatch sensitivity:
| Value | Sensitivity | Use case |
|---|---|---|
| 0.05 | Very strict | Exact pixel matching, catches everything |
| 0.1 | Default | Good balance, ignores most anti-aliasing |
| 0.2 | Lenient | Tolerates font rendering differences across systems |
| 0.3 | Very lenient | Only catches major color/layout differences |
node scripts/visual-diff.mjs \
--baseline temp/vdiff-baseline-desktop.png \
--current temp/vdiff-current-desktop.png \
--output temp/vdiff-diff-desktop.png \
--threshold 0.2
# 1. Screenshot baseline (production site hero)
mcp_playwright_browser_navigate → { url: "https://www.bitovi.com/" }
mcp_playwright_browser_resize → { width: 1280, height: 720 }
mcp_playwright_browser_wait_for → { time: 2 }
mcp_playwright_browser_snapshot → {}
# Find ref for hero section, e.g. ref="hero-[1]"
mcp_playwright_browser_take_screenshot → {
type: "png",
element: "hero section",
ref: "hero-[1]",
filename: "temp/vdiff-baseline-hero-desktop.png"
}
# 2. Screenshot current (Storybook story)
mcp_playwright_browser_navigate → { url: "http://localhost:6006/iframe.html?id=components-hero--default" }
mcp_playwright_browser_resize → { width: 1280, height: 720 }
mcp_playwright_browser_wait_for → { time: 3 }
mcp_playwright_browser_take_screenshot → {
type: "png",
filename: "temp/vdiff-current-hero-desktop.png"
}
# 3. Run diff (in terminal)
node scripts/visual-diff.mjs \
--baseline temp/vdiff-baseline-hero-desktop.png \
--current temp/vdiff-current-hero-desktop.png \
--output temp/vdiff-diff-hero-desktop.png
# 4. Start temp server (once per session, in background terminal)
npx -y http-server temp/ -p 8787 --cors -c-1 &
# 5. View diff image via Playwright
mcp_playwright_browser_navigate → { url: "http://localhost:8787/vdiff-diff-hero-desktop.png" }
mcp_playwright_browser_take_screenshot → {} # triggers vision
# 6. Interpret: read JSON output + visually inspect diff
# 7. Fix styles, re-screenshot current, re-diff
All output files go to temp/ which is gitignored. To clean up after a session:
rm -f temp/vdiff-*.png
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub bitovi/ai-enablement-prompts --plugin playwright8 skills in this plugin
/computed-stylesExtract and compare computed CSS styles between a baseline URL and a dev/Storybook URL using Playwright MCP evaluate calls. Use when visual differences have been identified and you need to find the exact CSS property mismatches to fix. Pairs with the visual-diff skill for a complete visual QA workflow./debug-e2e-testDebug and fix failing Playwright E2E tests. Use when tests fail, when asked to fix failing tests, or when investigating test failures. Analyzes test output, screenshots, error context, and uses Playwright MCP to identify root causes./debuggingAlways start a fresh browser session after any file change, walk through the full user flow, and monitor for errors before proceeding with further work./discover-visual-statesDiscover all visual states of a component by interactively exploring the production baseline page — not by reading story files. Finds every interactive element (nav items, dropdowns, toggles, buttons) that produces a distinct visual state, records the interactions needed to reach each one, and saves a pixel-perfect.config.json that the pixel-perfect skill uses to replay those same interactions on both production and Storybook. Run this once per component; re-run when the production page changes./pixel-perfectOrchestrate a complete visual QA workflow to make a dev/Storybook page match a baseline URL pixel-for-pixel. Combines the visual-diff skill (screenshot comparison) with the computed-styles skill (CSS property extraction) in a loop until the pages match. Use when replicating a production page, matching a design reference, or achieving pixel perfection on a component./test-responsive-designMake UIs responsive across all devices and verify responsiveness using Playwright. Includes scrollbar testing, breakpoint verification, and layout validation. Use when implementing new features, fixing layout issues, or ensuring mobile compatibility.Other plugins' skills for the same job