/playwright:discover-visual-statesfrom playwright
Explores a production page to discover all interactive visual states of a component and saves them as a config file for the pixel-perfect skill to replay on both production and Storybook.
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.
Explore the production page to discover every distinct visual state a component can be in. Save the interactions needed to reach each state to pixel-perfect.config.json. The pixel-perfect skill then replays those same interactions on both production and Storybook — no separate story per state required.
pixel-perfect on a component for the first timepixel-perfect.config.json does not exist yet for a componentpixel-perfect.config.json already exists and is up to date (pixel-perfect will tell you)| Input | Required | Example |
|---|---|---|
| Baseline URL | Yes | https://www.bitovi.com |
| Component scope hint | Yes | navbar, header nav, [aria-label="Main navigation"] — narrows which part of the page to inspect |
| Storybook default story URL | Yes | http://localhost:6007/iframe.html?id=components-meganavbar--default&viewMode=story |
| Config output path | Auto-derived | temp/MegaNavBar/pixel-perfect.config.json — always temp/{ComponentName}/pixel-perfect.config.json |
{
"baselineUrl": "https://www.bitovi.com",
"storybookUrl": "http://localhost:6007/iframe.html?id=components-meganavbar--default&viewMode=story",
"configPath": "temp/MegaNavBar/pixel-perfect.config.json",
"states": [
{
"label": "default",
"description": "Component in resting state — no interactions",
"interactions": []
},
{
"label": "services-dropdown",
"description": "Services dropdown open",
"interactions": [
{ "type": "hover", "target": "text:Services" }
]
},
{
"label": "our-work-dropdown",
"description": "Our work dropdown open",
"interactions": [
{ "type": "hover", "target": "text:Our work" }
]
},
{
"label": "contact-form",
"description": "Contact form panel open",
"interactions": [
{ "type": "click", "target": "text:Contact Us" }
]
}
]
}
Derive the config path from the component name: temp/{ComponentName}/pixel-perfect.config.json
(e.g. MegaNavBar → temp/MegaNavBar/pixel-perfect.config.json). Create the directory if it does not exist.
Look for pixel-perfect.config.json at that path.
mcp_playwright_browser_evaluate to find the component root element using the scope hint:() => {
const el = document.querySelector('[aria-label="Main navigation"]')
|| document.querySelector('nav')
|| document.querySelector('header');
return el ? {
tag: el.tagName,
id: el.id,
class: el.className.substring(0, 100),
rect: el.getBoundingClientRect()
} : null;
}
Within the scoped component, find all elements that can produce a distinct visual state. Run this evaluation:
() => {
const scope = document.querySelector('[aria-label="Main navigation"]') || document.querySelector('nav');
if (!scope) return [];
const candidates = [];
// Buttons and role=button elements
scope.querySelectorAll('button, [role="button"]').forEach(el => {
if (el.offsetParent === null) return; // skip hidden
candidates.push({
type: 'button',
text: el.textContent.trim().substring(0, 40),
ariaExpanded: el.getAttribute('aria-expanded'),
ariaLabel: el.getAttribute('aria-label'),
});
});
// Links that might reveal sub-menus
scope.querySelectorAll('a[aria-haspopup], li[aria-haspopup]').forEach(el => {
candidates.push({
type: 'link-with-popup',
text: el.textContent.trim().substring(0, 40),
});
});
// List items with cursor:pointer that aren't plain links
scope.querySelectorAll('li').forEach(el => {
if (window.getComputedStyle(el).cursor === 'pointer') {
const text = el.querySelector('button, a')?.textContent?.trim()?.substring(0, 40);
if (text) candidates.push({ type: 'clickable-li', text });
}
});
return candidates;
}
Deduplicate by text. This gives a raw list of interactive elements.
For each candidate, probe it by hovering and clicking to see if the page changes:
hover first, then click if hover produces nothing):
mcp_playwright_browser_snapshot to find the element ref by its textmcp_playwright_browser_hover or mcp_playwright_browser_click() => {
// Find elements that became visible (have content and are now visible)
return Array.from(document.querySelectorAll('[aria-expanded="true"], [class*="dropdown"][style*="block"], [class*="open"], [class*="active"]'))
.filter(el => el.offsetParent !== null)
.map(el => ({ tag: el.tagName, class: el.className.substring(0, 60) }));
}
For nav items and dropdowns, prefer hover if it opens the state — it more accurately reflects the production behavior. Use click for toggles (contact forms, mobile menus, accordions).
Heuristic:
aria-expanded that changes on hover → use hoverclickhover for dropdowns, click for forms/panelsAssemble the states list:
{ label: "default", interactions: [] } as the first statelabel derived from the element text (e.g. "Services" → "services-dropdown", "Contact Us" → "contact-form")Show the proposed config to the user in a formatted block:
Discovered N visual states for [component] on [baselineUrl]:
✅ default → no interactions (resting state)
✅ services-dropdown → hover "Services"
✅ our-work-dropdown → hover "Our work"
✅ community-dropdown → hover "Community"
✅ contact-form → click "Contact Us"
Storybook URL: http://localhost:6007/iframe.html?id=...--default
Does this look correct? Confirm to save, or describe any changes needed.
Wait for user confirmation before saving.
Navigate to the storybookUrl. For each state (except default), attempt the interaction on the Storybook component using the same text/role target.
"storybookWarning": "element not found"This catches mismatches early — e.g. if the Storybook component uses different text for a button.
Write pixel-perfect.config.json to the specified output path. Confirm the saved path to the user.
// Hover interaction
{ "type": "hover", "target": "text:Services" }
// Click interaction
{ "type": "click", "target": "text:Contact Us" }
// Keyboard interaction
{ "type": "keydown", "target": "text:Search", "key": "Enter" }
// Type into a field
{ "type": "type", "target": "label:Search", "value": "consulting" }
Target format:
text:X — find the first visible element whose trimmed text content is Xrole:button:X — find <button> or role="button" with accessible name Xlabel:X — find an input associated with label text Xselector:X — use X directly as a CSS selector (last resort)When replaying interactions in pixel-perfect, translate targets to Playwright MCP calls:
mcp_playwright_browser_snapshot → find the ref matching the target descriptionmcp_playwright_browser_hover / mcp_playwright_browser_click with that refUser: "Discover visual states for the MegaNavBar.
Baseline: https://www.bitovi.com
Scope: nav[aria-label='Main navigation']
Storybook: http://localhost:6007/iframe.html?id=components-meganavbar--default&viewMode=story
Config: temp/MegaNavBar/pixel-perfect.config.json"
Agent:
1. Navigate to https://www.bitovi.com
2. Dismiss cookie banner
3. Scope to <nav> — found navigation element
4. Discover interactive elements:
- Buttons: Services, Our work, Community, Contact Us
- Clickable LIs: About, Careers
5. Probe each:
- "Services" hover → dropdown appeared (Project management, Product design...) ✅
- "Our work" hover → dropdown appeared (Showcase, More Projects...) ✅
- "Community" hover → dropdown appeared (Blog, Academy...) ✅
- "Contact Us" click → form panel appeared ✅
- "About" click → navigates away — skip (full navigation, not a visual state)
- "Careers" click → navigates away — skip
6. Verify on Storybook:
- All 4 interactions work on Storybook default story ✅
7. Config saved to temp/MegaNavBar/pixel-perfect.config.json
5 states: default, services-dropdown, our-work-dropdown,
community-dropdown, contact-form
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
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./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./visual-diffCompare a baseline URL against a dev or Storybook URL by taking Playwright screenshots at multiple breakpoints, running a pixel-level image diff, and reporting results to guide style and HTML corrections. Use when replicating an existing page or component, verifying visual accuracy, or checking responsive fidelity.Other plugins' skills for the same job