Visual regression checks with CLI tool screenshot-drift
Updating a site is rarely the hard part. Knowing that nothing broke afterwards is.
A major framework update, a new theme version or a CSS refactoring shifts a heading by a few pixels on a single page. Or a merge quietly brings back an old translation file, and typos fixed months ago are live again. Clicking through every page in two viewports after each change is tedious, and by the 12th time I stop looking closely. That's why I wrote screenshot-drift.
What you get
Ten checks, four failures, and I know exactly where to look:

This run compared five pages of this very site in two viewports. Before the second run, I slipped in two typical mistakes. A CSS change drops the web font of blog post titles. And an old, unproofread translation file sneaks three tiny differences into the about page. Exactly those two pages fail, in both viewports. The other pages pass, because they really didn't change.
Besides screenshots, every page is checked for JavaScript errors, console errors, 5xx responses and PHP error output. A page can look perfect while a plugin throws a fatal error in the footer.
Three commands
$ npx screenshot-drift baseline
# ...update, refactor, deploy...
$ npx screenshot-drift test
$ npx screenshot-drift report
baseline takes full-page screenshots of all configured pages. test takes them again and compares. It exits with 0 if everything matches and 1 if not, so it works in scripts too. report starts a small local web server and opens the result in the browser.
Spotting the difference
A failed test opens with the diff view. It fades out the page and marks every changed pixel in red. Here's the about page:

Three red spots in a whole paragraph: swapped letters in "Commodore" and "understanding", and C46 instead of C64. Everything else is untouched. Would you have caught those by reading? After a while of clicking through pages, I would hardly notice changes like that anymore.
For layout and typography, side by side works better. Here's the blog post, expected on the left, actual on the right:

The serif title turned into a smaller sans-serif one, and the text below moved up.
For a shift of a pixel or two, side by side isn't enough. The slider lays both versions on top of each other, and the handle shows where they split:

The handle cuts right through the title: fallback font on the left, web font on the right, and the lines below no longer line up.
If a change is intended, I accept it for that one page:
$ npx screenshot-drift baseline -g "visual: blog-laravel"
Setup
$ npm i -D screenshot-drift
$ npx screenshot-drift install
$ npx screenshot-drift init
$ echo ".screenshot-drift/" >> .gitignore
install downloads Chromium once per machine, init writes a screenshot-drift.config.js:
module.exports = {
targets: { local: 'http://localhost:3000', prod: 'https://www.christian-doebler.net' },
pages: {
home: '/en',
about: '/en/about',
blog: '/en/blog',
'blog-laravel': '/en/blog/multiple-languages-in-laravel',
imprint: '/en/imprint',
},
mask: ['canvas'],
css: ['./screenshot.css'],
};
That's the setup behind the screenshots in this post. Each target gets its own baseline. Every page is captured on desktop (1440×900) and mobile (Pixel 7). The homepage has an animated canvas in its hero, so it's masked. I keep the page list short: one or two pages per template are enough.
The same picture twice
The hard part of screenshot testing isn't the comparison. It's getting the same picture twice. Lazy images, scroll animations, sliders, videos and dates produce diffs that mean nothing. After a few false alarms, nobody opens the report anymore.
So screenshot-drift calms the page down first. It loads lazy images, scrolls to trigger reveals, stops videos at the first frame, resets Swiper sliders, freezes the clock and disables CSS animations. Whatever is still random gets masked.
A diff should always mean that something changed. That's also why the allowed difference is 0 by default. On a long page, even 1% can hide a whole changed paragraph.
Real life isn't always that tidy, though. On this site, the sticky navigation bar landed at a different spot on mobile now and then. That's what screenshot.css in the config is for. Its styles are only injected while screenshotting:
nav.sticky { position: static !important; }
Production stays untouched
A local copy often still has production URLs somewhere: in the database, in a hard-coded asset, in a form action. screenshot-drift blocks requests to the hosts of all other targets and lists them in the report. A local test never touches prod, and I see right away which URLs still point to the wrong place.
Made for CI and AI agents
Exit codes, no prompts, and a results.json with the paths to all diff images. That's all a CI pipeline needs. It's also enough for an AI coding agent: run the tests after a refactoring, look at the diffs, fix what broke. For anything a screenshot can't check, custom Playwright specs can be added to the config.
What I like most: I can move a site to a new major version or rewrite half the stylesheet, and afterwards I know what changed instead of hoping that nothing did. screenshot-drift is MIT-licensed and available on GitHub and npm.
Have fun comparing screenshots!

