Prompt
I'm building a frontend CI pipeline and want screenshot diffs on every PR
Latest observation
Oct 27, 2026
OpenAI APIWeb search: off
A solid way to do this is:
- Run your app in CI
- Take screenshots of key pages/components
- Compare them against stored “baseline” screenshots
- Fail or comment on the PR if there’s a visual change
Recommended tools
- Playwright for browser automation and screenshot capture
- Percy, Chromatic, or Argos for hosted visual diffing
- Or do it yourself with Playwright + pixelmatch if you want full control
Best-practice setup
Option A: Hosted visual testing
This is the easiest for PRs.
Pros
- Easy PR comments with diffs
- Flake handling and baseline management
- Great UX for reviewers
Typical flow
- On every PR, run screenshots
- Upload to service
- Service compares against baseline
- PR gets pass/fail and a review link
Example tools
- Percy: good general-purpose visual regression
- Chromatic: excellent if you use Storybook
- Argos: nice for Playwright-based workflows
Option B: Self-managed with Playwright
Good if you want no external dependency.
Flow
- CI starts app
- Playwright runs screenshot tests
- Compare against checked-in baseline images
- If mismatched, CI fails and uploads diffs as artifacts
Example with Playwright
Install
npm i -D @playwright/test
npx playwright install --with-deps
Test example
// tests/visual.spec.ts
import { test, expect } from '@playwright/test';
test('homepage looks correct', async ({ page }) => {
await page.goto('http://localhost:3000');
await expect(page).toHaveScreenshot('homepage.png', {
fullPage: true,
});
});
CI workflow idea
- Build app
- Start server
- Run Playwright tests
- Upload diff artifacts on failure
Example GitHub Actions sketch:
name: visual-tests
on:
pull_request:
jobs:
screenshot-diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run build
- run: npm run start &
- run: npx wait-on http://localhost:3000
- run: npx playwright test
Important tips to reduce flaky diffs
- Use a consistent viewport
- Disable animations
- Wait for fonts to load
- Mock API/data for deterministic rendering
- Run in Docker/Linux in CI and match local fonts if possible
- Prefer component/route-level screenshots over entire app if possible
Baseline management
A good pattern is:
- PRs: compare against main branch baselines
- Main branch merges: update baselines intentionally
- Require a human approval to accept new screenshots
If you want the best reviewer experience
Use:
- Playwright for capture
- Percy/Chromatic/Argos for diff UI and PR comments
If you want, I can give you:
- a GitHub Actions workflow for Playwright screenshot diffs, or
- a Percy/Chromatic setup depending on your stack.