AGENT SKILL

web-ui-verification

Verify web UIs via headless Chrome CDP, no vision needed.

License 许可
MIT
最近更新
2026-08-16
Stars
★ 0
Forks
0

01 前言 Front Matter

name
web-ui-verification
tags
[ "web", "ui", "verification", "testing", "chrome", "cdp", "headless", "design-audit" ]
author
Hermes Agent
license
MIT
version
1.0.0
triggers
[ "verify the page renders", "check the UI against a spec", "screenshot the site", "test button hover / modal / palette interactions", "check console errors", "computed style audit", "design system fidelity check" ]
platforms
[ "linux", "macos", "windows" ]
description
Verify web UIs via headless Chrome CDP, no vision needed.

02 资源文件 3

03 SKILL.md 正文

Web UI Verification (headless Chrome via raw CDP)

Deterministic verification of web UIs when the normal browser tool can't reach the page (file:// / localhost URLs blocked by the browser backend) or when browser_vision is unavailable. No Playwright/puppeteer/npm needed — just a Chrome/Chromium binary and Node's built-in WebSocket (Node >= 22 has global WebSocket).

When this fires

  • The browser tool refuses private/localhost URLs. Serve the page with python3 -m http.server <port> --bind 127.0.0.1, show it to the user via open_preview(localhost:<port>/...), and verify it yourself with this harness.
  • The vision provider is text-only (image analysis fails with unknown variant image_url). The computed-style audit below is a stronger fidelity check than eyeballing anyway.
  • npm/Playwright install is network-blocked — raw CDP needs only the Chrome binary.

Faster path: puppeteer MCP browser (when available)

The mcp__puppeteer__* toolset runs its own headless Chrome and DOES reach localhost when the main browser backend blocks it — a full interactive E2E + screenshots in minutes:

mcp__puppeteer__puppeteer_navigate   { url, launchOptions: { headless: true,
                                       args: ['--no-sandbox', '--disable-gpu'] },
                                       allowDangerous: true }
mcp__puppeteer__puppeteer_fill       { selector: '#email', value }
mcp__puppeteer__puppeteer_click      { selector: 'button[type=submit]' }
mcp__puppeteer__puppeteer_screenshot { name, width: 1440, height: 900 }

Screenshots land in ~/.hermes/cache/images/img_*.png (share via MEDIA: path). Auth'd flows work: fill → click → next navigate keeps the session cookie. Then verify pixels (see below) — don't rely on the vision provider.

Pixel-level token verification (no vision)

Screenshot → color analysis with the bundled probe:

env -u PYTHONPATH python3 scripts/pixel-token-check.py <shot.png>

It reports canvas/card region averages, token pixel counts (gold-500 primary, silver borders/text, semantic states), and an ASCII layout map — enough to prove design-system compliance (Mavis or any token set, pass --tokens NAME=#RRGGBB for custom scales). Tolerances: 18/channel exact tokens, ~24 for brand colors. Rich-content proof: high dark text-pixel counts on table views = data rendered, not blank cards. For zoomed region inspection ("is the subject visible in the hero band?"), use scripts/ascii-region-view.py <shot.png> x0,y0,x1,y1 cols rows — renders any crop as an ASCII luminance map so the composition (headline, subject mass, glow, road band) reads in text.

Workflow

  1. Launch Chrome headless as a background process: google-chrome --headless=new --disable-gpu --no-sandbox --disable-dev-shm-usage --remote-debugging-port=9333 --user-data-dir=/tmp/cdp-profile --window-size=1440,1000 about:blank
  2. Poll http://127.0.0.1:PORT/json/version until it responds (CDP is up).
  3. Open a tab: PUT http://127.0.0.1:PORT/json/new?<encoded URL> → returns {webSocketDebuggerUrl}.
  4. new WebSocket(webSocketDebuggerUrl); wire a pending-map (id → resolve) for responses and collect Runtime.consoleAPICalled + Runtime.exceptionThrown for the zero-error report.
  5. Runtime.enable, Page.enable, sleep ~2.5s (plain pages) then await document.fonts.ready before measuring. WebGL/Three.js pages need ~6s: headless Chrome's SwiftShader software rasterizer is slow to first paint — screenshots taken at 2–3.5s show blank/near-dark frames and produce false "scene is broken" alarms. On mobile emulation (setDeviceMetricsOverride + mobile:true) settle ~6.5s.
  6. Run checks via Runtime.evaluate (returnByValue:true, awaitPromise:true).
  7. Screenshots via Page.captureScreenshot (PNG base64). For full-page shots set Emulation.setDeviceMetricsOverride width/height to document.documentElement.scrollHeight, then restore.
  8. Real hover via Input.dispatchMouseEvent {type:'mouseMoved', x, y}.
  9. Kill Chrome when done.

Copy templates/cdp-harness.mjs — all of this is wired and ready to edit.

Pitfalls (learned the hard way)

  • Synthetic key events: dispatching a KeyboardEvent on document/window can miss document-level listeners. Dispatch on document.body or the focused element so it bubbles; for inputs set .value first, then dispatch new Event('input',{bubbles:true}).
  • Smooth scroll breaks mouse coordinates: html{scroll-behavior:smooth} makes scrollIntoView animate — a freshly read getBoundingClientRect() can be mid-flight. Use behavior:'instant', then confirm the landing spot with document.elementFromPoint(x,y) before dispatching mouse events.
  • :hover is not queryable: querySelector('.btn:hover') is invalid. Check hover styles by moving the mouse for real and re-reading getComputedStyle, or scan document.styleSheets cssRules text for the hover rule.
  • Headless Chrome reports prefers-color-scheme: dark even for "light" designs, silently flipping dark-mode CSS. Add a ?theme= deep-link override to the page (or emulate the scheme) and assert the active theme before any color assertions.
  • Full-page screenshots: Page.captureScreenshot captures only the viewport — override device metrics to scrollHeight first.
  • Zero-error guarantee: subscribe to console/exception events before the page's scripts run; report both in the final summary, not just Runtime.evaluate results.
  • Heredocs trip the command guard: python3 - <<'EOF' … EOF via the terminal tool can fail with "embedded null byte" (the lifecycle guard scans referenced scripts). Always write_file the script to /tmp and execute the file instead — also true for signup / auth-flow / probe scripts.
  • gl.readPixels returns zeros on Three.js pages: preserveDrawingBuffer:false (Three default) means the back buffer is consumed by compositing, so raw GL pixel probes read all-0 even when the scene renders fine. Trust Page.captureScreenshot (the composited truth) and pixel-stat the PNG instead of reading GL directly.
  • Blank-looking WebGL frames on the first screenshot: SwiftShader first paint lags ~5–6s (see step 5). Before concluding "canvas is empty", re-shoot after a longer settle — the earlier frame is a false alarm, not a scene bug.
  • Mobile emulation: Emulation.setDeviceMetricsOverride with mobile:true + deviceScaleFactor:2 — then assert the matchMedia query fired, check document.documentElement.scrollWidth - clientWidth for overflow, and re-shoot each section; a viewport-only resize doesn't re-layout fixed/full-screen canvases.

Computed-style audit (design-fidelity verification)

When verifying against a design spec, assert instead of eyeball:

  • getComputedStyle(el).backgroundColor/color/fontSize/lineHeight/borderRadius/boxShadow compared to spec tokens in rgb() form (e.g. #A87C2A → rgb(168, 124, 42)).
  • line-height math: computed px = unit × factor (16px × 1.55 = 24.8px).
  • Overflow scan: elements with scrollWidth > clientWidth + 2 and overflow-x not auto/hidden/scroll — exclude intentional positioned children (e.g. tooltips via el.closest('.tip-wrap')).
  • Geometry: assert sidebar right ≤ main left (no overlap), fixed topbar overlapping the hero is intentional, etc.
  • Element counts: expected swatches, type rows, buttons, icon cells.
  • Tabular numbers: fontVariantNumeric includes tabular-nums.

Related

  • popular-web-designs — design templates; its "verify with browser_vision" step can be replaced by this skill's audit.
  • dogfood — exploratory QA with interactive browser tools; complementary when those tools can reach the page and you want free-form bug hunting instead of scripted checks.

04 同仓库更多 Skills