Before and after screenshots of a web page, with the change marked, ready to paste in a pull request.
- On the before shot, a red box goes around what was removed.
- On the after shot, a green box goes around what was added.
- The boxes only point at a change: nothing is painted over the page, so what is inside one looks as it does on the page.
- A change with no words in it is marked too: a box says what changed on an element whose look changed (a colour, a border, a size), or on a picture redrawn under the same file name.
- A component added or removed, a card, a row, a paragraph, gets one plain box, red or green, and nothing inside it is marked.
- Each image has a band on top with its side, your title, and what its colour means. A lone image,
with
--unified, says Removed or Added instead of its side.
A dashboard where numbers, a row, a chart and some styles changed:
| Before | After |
|---|---|
![]() |
![]() |
More in examples/, each with its command.
You need Node.js 22.18 or later. You give it two addresses of the same page, before and after the change, and a title:
npx @yannickbaudraz/shot-diff <before-url> <after-url> --title "What changed"It writes shot-before.png and shot-after.png in the current folder. The first run may ask to
download a browser (see Browser).
You need the page as it was and the page as it is now, both reachable at the same time. Pick the first way that fits.
1. The site is already online, and the pull request has a preview. Many projects deploy each pull request to its own address (Netlify, Vercel, Cloudflare Pages, GitHub Pages): look for a "deploy preview" link in the pull request's checks or comments. Use the live site as before and the preview as after. Nothing to install or start:
npx @yannickbaudraz/shot-diff \
'https://<live-site>/pricing' \
'https://<preview>/pricing' \
--title "Pricing: the new plans" --selector mainReplace <live-site> with your site's address, and <preview> with the address the preview link
opens. Each host names its previews its own way: on Netlify, for instance, it looks like
deploy-preview-123--my-site.netlify.app. A preview usually lasts only while its pull request is
open: take the shots before it is merged or closed.
The live site may have moved on since the pull request started; those changes show up too. Compare with a preview of the base branch instead when the project has one.
2. The site builds to static files. Build each version into its own folder and point at the files, no server needed:
git worktree add ../before main # the base branch, next to your checkout
(cd ../before && npm ci && npm run build)
npm run build # your branch
npx @yannickbaudraz/shot-diff file://$PWD/../before/dist/index.html file://$PWD/dist/index.html --title "Home"The build folder may be dist, build or out, depending on the project. If the page comes out
without its styles, the build links its files from the site's root, which a file:// address does
not have: serve each folder instead, with npx serve dist -l 3000 and -l 3001, and use way 3.
3. The app needs a server. Start the base branch on one port and your branch on another, then point at both:
npx @yannickbaudraz/shot-diff http://localhost:3000/cart http://localhost:3001/cart --title "Cart: the empty state"Both pages load at the same size, in the same colour scheme, with the same stored settings and clicks, so the only difference is the change.
By default it shoots the area around the changes, wherever they are. When the page has changes you
do not care about (a rotating ad, a date, a menu), name the part you do care about with
--selector:
--selector main # or article, .content, #pricing: any CSS selectorOnly the changes inside that element count: in it in the page's HTML, not just drawn over it.
Everything else is ignored, a menu above it, a column beside it, a wrapper around it: it is in no
image and left unmarked, and the command says how many changes it ignored. The shots are still cut
around the changes inside the element, not the whole element, and as wide as the element with
--padding on each side (never narrower than 400 pixels, so the title fits): a column of a page is
shot as a column. The width follows the element you name, not where the changes are: #rules, a
section across the page, gives a shot across the page; name the column inside it to narrow it. A
change drawn past the element (a dropdown, a tooltip) widens the shot to take it in.
To find a selector, open the page in your browser, right-click the part you want, choose
Inspect, and use the element's id (#name) or a class (.name) shown there. Or let the
command find them:
shot-diff <before> <after> --dry-run--dry-run does all a run does but the screenshots, with every other option taking effect: it lists
the images it would write, with their sizes, and then the parts of the page that changed, each as a
--selector to run it with:
would write shot-1-before.png: 3 part(s) removed, 1280x1304 px
would write shot-1-after.png: 4 part(s) added, 1280x1343 px
2 part(s) of the page changed; for a pair of images of each, run once per part with its --selector:
--selector '#step-14' 2 change(s)
--selector '#rules > div:nth-child(2) > div:nth-child(1)' 13 change(s)
A part is the widest element around a change that is still clearly narrower than the page, a card
or a column, so its shot is narrow; with none, the nearest element with an id. Changes in no part
are listed last: a run with --selector leaves them out, so they need one more run without it. It
needs no --title, as it writes no image; --json gives the same list under areas.
examples/ shows each of these: the command, what it prints, and its images.
- A size on each image's line, such as
shot-after.png: 2 part(s) added, 640x1350 px: in the CSS pixels--heightand--max-heightcount in (the file is that at--scale, with its band). - One pair of images when all the changes fit in one image.
- Several numbered pairs (
shot-1-before.png,shot-1-after.png,shot-2-…) when changes are far apart. The band says "1 of 3", and so on. - One image for a pair, with
--unified, when all its changes are removals or all are additions:shot.png, the before shot with its red boxes, or the after shot with its green ones. The other image would only show the same place with nothing marked. With no other image to tell it from, its band says Removed or Added instead of Before or After, and its file name has no side. Each pair is decided by itself: of several, the others keep both images (shot-1-before.png,shot-1-after.png,shot-2.png), and the numbers in the file names stay the same. - "N change(s) are cut from every image" on the terminal: a change is taller than one image may
be, which is 1.5 windows by default. Raise
--max-height, or narrow the shot with--selector. - "N image(s) are taller than two windows": an image more than twice as tall as
--height. In a pull request it is shrunk to the width of the text and is a lot of scrolling, so the before and the after cannot be compared by eye. The default--max-height, 1.5 windows, never gives one: it comes up when you raised it. Lower it, or shoot one part with--selector. - "N change(s) outside --selector ignored": changes it found outside the element you named. That
is expected;
--jsonlists them underignoredif you want to check. - "N change(s) are in a part of the page a scroll area cuts off": the change is on the page, but inside a scroll area (a sidebar, a code block, a panel) past what it shows, so no screenshot can show it. The list tells you what to look at in the browser.
- "no difference": both pages look the same to it. Check the two addresses are really the two versions.
--json prints all of this as JSON: for each image, its file, what it marks and where (null for
the image --unified leaves out, the one kept being under its side); then leftOut (cut from every
image), hidden (cut off by a scroll area) and ignored (outside --selector).
When the page needs more than a click before it looks right (something typed, a login, items in a
cart), add --interactive:
npx @yannickbaudraz/shot-diff http://localhost:3000/cart http://localhost:3001/cart \
--title "Cart: two items" --interactiveTwo Chrome windows open, one on each page, and the terminal says which address is the before page
and which is the after. Do the same thing in both windows: click, type, log in. Then go back to the
terminal and press Enter: both pages are shot as you left them. Answer n instead to stop without
shooting.
- Do the same steps in both windows. Anything you do in one only shows up as a change.
- Keep one tab per window. Only one can be shot. If a link opened another, close the ones you do not want: it asks again until each window has one tab left, and shoots that one.
- Scroll both pages to the same place, or back to the top: a header that stays on screen is drawn where each page is scrolled to.
- What shows only while the pointer is over it (a tooltip, a hover colour) is not shot: the pointer can be over one window only, so it is taken off both.
- It needs a screen, and you at the terminal. On CI, use the options below instead.
- The size of a window does not matter. Each page keeps the size set with
--widthand--height, however you resize its window, so both are always the same size. And the images are cut around the changes, not around what the window shows: to shoot one part, use--selector.
Add --tabs to get one window with the two pages as tabs, not a window each:
npx @yannickbaudraz/shot-diff http://localhost:3000/cart http://localhost:3001/cart \
--title "Cart: two items" --interactive --tabs- Resize the window to choose the size of the page: both tabs take it, a moment after you let go, as on a narrower or wider screen. That is the size the pages are shot at.
- The window must have two tabs when you press Enter, the before page and the after page. A tab one of them opened can take its place; close any other.
- One window is one browser session. The two pages share their cookies when they are on the
same host, and
localhost:3000andlocalhost:3001are: a login or a cart kept in a cookie on one applies to the other. With two windows, each page has its own. - On WSL, the windows are Chrome for Windows (see Browser).
The same every time, with nobody there:
| You want | Add |
|---|---|
| A phone-sized page | --width 390 --height 844 |
| Dark mode | --dark |
| A menu or dialog opened first | --click "#menu-button" (repeat for several clicks, in order) |
| A setting the page reads at load, such as a dismissed banner | --storage banner-closed=true |
| More time for the page to settle | --wait 1000 (milliseconds) |
| Numbered boxes, explained in the band, instead of labels over the page | --markers numbers |
| Option | Default | What it does |
|---|---|---|
--title <text> |
required, unless --dry-run |
the title in the band |
--out <dir> |
. |
the folder the images go in |
--name <name> |
shot |
the start of the file names: <name>-before.png, <name>-after.png, or <name>.png for a lone image with --unified |
--selector <css> |
only count the changes inside this element, and cut the images to its width | |
--dry-run |
do all of a run but the screenshots: list the images it would write, and the parts of the page that changed with a --selector for each |
|
--unified |
a pair whose changes are all removals is its before image alone, and one whose changes are all additions its after image alone: <name>.png, its band saying Removed or Added |
|
--width, --height |
1280, 900 | the browser window, in pixels |
--scale |
2 | pixel density: 2 makes sharp images, 1 smaller files |
--dark |
dark colour scheme | |
--storage key=value |
set in localStorage before the page runs (repeatable) |
|
--click <selector> |
click after loading, in order (repeatable) | |
--wait <ms> |
300 | wait after loading and clicking |
--interactive |
open both pages in windows, and shoot them once you have set them up by hand | |
--tabs |
with --interactive: one window with both pages as tabs, which you can resize |
|
--ignore <css> |
leave these elements, and all inside them, out of the comparison, for parts showing other data (prices, dates, a live counter); repeatable, each selector matching every element it fits; they still show in the shots, unmarked. --json says how many each matched on each page |
|
--show-ignored |
box what --ignore leaves out in dashed grey, saying "ignored", so a reader can tell it was left out on purpose, not missed |
|
--no-words |
compare no words, for pages whose text differs anyway (random text, other data): only changes of look, and elements added or removed, are marked; elements are paired by what they are, not by what they say | |
--markers labels|numbers |
labels |
on a box around a change of look: what changed written on it, or a number explained in the band |
--padding <px> |
80 | room kept around the changes |
--max-height <px> |
1.5 × --height |
the tallest an image gets (1350 at the default --height); changes further apart get their own pair |
--chrome <path> |
Google Chrome, or $CHROME |
another Chrome or Chromium to use |
--download, --no-download |
ask | without Chrome: download one without asking, or stop |
--json |
print what was marked, where, and what was left out or ignored |
It uses Google Chrome if it is installed, without opening a window, except with --interactive.
Without it, it offers to download Playwright's Chromium (about 100 MB, once; about 200 MB for the
one that opens windows, with --interactive) and waits for a yes. Where nobody can answer,
as on CI, it stops instead: add --download to allow the download up front, or --chrome <path>
to use another Chrome or Chromium.
On WSL, --interactive opens Chrome for Windows, the one on your desktop, not the Linux one. It
starts it with a profile of its own, removed after: your tabs, logins and extensions are not in it.
A file:// page in WSL is opened from Windows, and localhost is the same on both. The pages are
then drawn with Windows fonts, so the shots differ a little from the ones made without
--interactive, which the Linux Chrome draws. This needs Chrome installed on Windows, and WSL
sharing localhost with it (networkingMode=mirrored in .wslconfig); otherwise the Linux Chrome
opens. To get the Linux one anyway, name it: --chrome /usr/bin/google-chrome.
- It loads both pages in Chrome through Playwright and reads every visible word and image, in the order the page shows them, inside web components (their shadow trees) too. Hidden text is left out.
- It diffs the two word lists (Myers' algorithm, as
git diffuses for lines, from thediffpackage). - On the before page it boxes the removed words in red; on the after page it boxes the added words in green: one outline around a run of words over several lines, shaped as a text selection is, or one box around a block whose words all changed. Lines with no width under both, as the end of one line and the start of the next, get a box each. The side of a box stays off an unchanged word written against the changed one. The boxes are drawn over the page in an overlay, with a white ring outside them, so nothing on it moves and a box shows on a background close to its colour. A box of words is filled with a faint tint of its colour: two changes a line apart box the unchanged words between them on three sides, and the tint tells what changed from what the lines only go round. A changed picture gets no tint, nor does the box of an element: they show as the page has them.
- It pairs the elements of the two pages the same way, by tag, id, role, own words and image file,
and an element with no words of its own (a list item, a row, a card) by its first words, so an
item inserted in a list does not take the place of the one it pushed down; then, between two elements it paired, the ones left over on both pages by their tag alone, so an
element whose words changed is still paired with the one in its place. It compares what the
browser computed for each pair: colours, borders, corners, shadow, font,
spacing, alignment, and the size of elements with nothing inside them. A border or an outline
counts only where one is drawn. Images, canvases, SVGs, embedded pages (iframes) and backgrounds
with no element inside them that kept their style are compared pixel by pixel
(pixelmatch), at the smaller of their two sizes when the
layout scaled one.
An element that only one page has, with nothing inside it that the other page has too, is a
change as well, removed on the before shot and added on the after. It is a component when it
has no word or image in it, or is a block of its own (a paragraph, a card, a table row); a link
in a sentence is not, and stays a change of words. One inside another is the outer one's, so a
card added is boxed once, and what is inside it is not marked. The words of a component are left
out of the word diff, so they pair with no word on the other page.
When all the children of one kind of an element changed alike, the links of a menu, the cells of
a row, the change is written once on that element, as "spacing, layout · 4 links: spacing", not
on each child; one child that changed otherwise leaves each its own box, and so does a parent
that is the page's body or taller than
--max-height. A change of look gets a box with what changed written on it, or a number explained in the band with--markers numbers. A component added or removed gets a plain box, as changed words do: its colour says it, red on the before shot, green on the after. On the page without it, the shot takes in whole the element next to where it would be. - It shoots the area around the changes, unchanged words next to each change included, and the
heading of what a change is in (a card's title, a section's heading) when it is less than a
window high above it. Both shots of a pair show the same place: each edge of one is put on the
other page by the unchanged words near it, so a row of cards that grew on one page is shot from
the same card titles on both, even when one side of a change is empty. With
--selector, it first drops the changes outside the element's tree, and takes their marks off, and the shots are as wide as the element, the same on both pages. A box goes around what a scroll area shows of a change; a change it shows none of gets no box and is listed instead. Changes far apart are shot apart, and an edge of a shot never cuts a line of text in half: it goes to the room before or after that line. A shot never opens inside an item (a list item, a paragraph) either: its top goes up to the top of the item, or down to the top of the next one when going up would make the shot taller than--max-heightand the change stays in. The bottom is cut on a line only. With--unified, a pair whose changes are all removals is shot on the before page alone, and one whose changes are all additions on the after page alone, as<name>.png. A change of look, which both pages have, keeps both. - It draws the band on each shot with sharp. A lone image's band says Removed or Added instead of its side, and leaves out the colour key.
- An element is matched across the pages by its tag, id, role, own words (its first words, with none of its own) and image file. One whose words changed is matched with the element of the same tag in its place, and a change of its look is marked beside its words; where elements were also added or removed around it, that match can be with a neighbour. One that moved elsewhere in the page is not matched, and with no words in it is marked removed where it was and added where it is.
- Among elements alike, with no words to tell them apart, the one added or removed cannot be told from its neighbours: of three dividers where there were two, the box may go on another than the new one.
- A component is told apart by what is in it: when an element inside it matches one the other page has, as a "Buy" button identical to an existing one does, the component is not "added" whole, and what is new in it is marked each by itself. Rows of a table, and other elements alike, are paired by their place; one whose contents match none of the old one's is taken for a new row, so a row added is one box even when its cells repeat those of other rows.
- A component put where another was, a card replaced by a different card, is paired with the old one by its tag and shown as changed words, not as one removed and one added.
- A component taller than
--max-heightis shown by its top: its box runs off the bottom of the shot. - Pseudo-elements (
::before,::after) and position on the page are not compared: an element pushed down by text added above it is not a change. - Moved text shows as removed in one place and added in another.
- A changed word written against an unchanged one, with no space between, as a comma after a link: the line of its box goes between them, over the edge of the changed one, so the unchanged one stays whole.
--no-wordsleaves out the words only. Where the data differs, the structure often does too: rows, items or cards that only one page has are still marked added or removed, and a chart or an image drawn from other data is still marked redrawn. Leave such areas out with--ignore, or name the part you care about with--selector.- A background image redrawn under the same file name is marked only on an element with no other element inside it: a shot of a banner with a heading on it holds the heading too, so its pixels are not compared. A background whose file name changed is marked, as a change of style.
- The words inside an embedded page (an iframe) are not read. When it is drawn differently, the
whole iframe is boxed as an "embedded page", without saying what changed in it. One that differs
from one load to the next, as an ad or a video does, is boxed too: name the part you care about
with
--selectorto leave it out. - A web component's shadow tree is read when it is open, as most are. A closed one cannot be reached
from the page, so a change inside it is not seen.
--selectorfinds its element in the page itself, not inside a shadow tree; the shadow trees inside that element count.
npm install
npm test # vitest, needs Chrome: units in Node, src/page/runtime.ts in Chrome (browser mode)
npm run test:e2e # the command on fixture pages, and its images against e2e/__image_snapshots__
npm run test:e2e -- -u # update the reference images after a change meant to alter them
npm run check # types
npm run build # vite: dist/cli.jsThe reference images depend on the fonts of the machine that made them, so CI does not compare them.

