Prompt
How do I compare screenshots across Chrome and Firefox?
Latest observation
To compare screenshots across Chrome and Firefox, the most reliable approach is to make the capture environment as consistent as possible, then compare the images with a visual diff tool.
1) Keep the rendering conditions identical
Make sure both browsers use:
- the same OS and display scaling
- the same viewport size
- the same zoom level
- the same font settings if possible
- the same page state/data
- the same device pixel ratio if you can control it
Small differences in anti-aliasing, fonts, and subpixel rendering are normal between Chrome and Firefox.
2) Take screenshots in both browsers
You can do this manually, or automate it with tools like:
- Playwright
- Puppeteer (Chrome-centric, but can run Firefox in some setups)
- Selenium
If you’re doing visual regression testing, Playwright is usually the easiest because it supports both browsers.
Example with Playwright:
import { chromium, firefox } from 'playwright';
async function capture() {
const url = 'https://example.com';
const chrome = await chromium.launch();
const firefoxBrowser = await firefox.launch();
const chromePage = await chrome.newPage({ viewport: { width: 1280, height: 800 } });
const firefoxPage = await firefoxBrowser.newPage({ viewport: { width: 1280, height: 800 } });
await chromePage.goto(url);
await firefoxPage.goto(url);
await chromePage.screenshot({ path: 'chrome.png', fullPage: true });
await firefoxPage.screenshot({ path: 'firefox.png', fullPage: true });
await chrome.close();
await firefoxBrowser.close();
}
capture();
3) Compare the images with a diff tool
Good options:
- Pixelmatch (Node.js)
- Resemble.js
- ImageMagick
- Percy, Applitools, or Chromatic for hosted visual testing
Example with pixelmatch:
import fs from 'fs';
import pixelmatch from 'pixelmatch';
import { PNG } from 'pngjs';
const img1 = PNG.sync.read(fs.readFileSync('chrome.png'));
const img2 = PNG.sync.read(fs.readFileSync('firefox.png'));
const { width, height } = img1;
const diff = new PNG({ width, height });
pixelmatch(img1.data, img2.data, diff.data, width, height, {
threshold: 0.1
});
fs.writeFileSync('diff.png', PNG.sync.write(diff));
4) Decide what differences matter
Browsers often differ slightly in:
- font rasterization
- line spacing
- scrollbars
- shadows/gradients
- image interpolation
- default form control styling
So compare with a tolerance threshold rather than expecting pixel-perfect matches.
5) If you only need to inspect differences manually
You can:
- open both screenshots in an image editor and flip between them
- use an image comparison website/tool
- overlay them with transparency to spot changes
Best practice
For cross-browser screenshot comparison, use:
- Playwright for capture
- pixelmatch or a visual regression service for diffing
- a fixed viewport and controlled environment
If you want, I can give you:
- a Playwright script for Chrome + Firefox, or
- a Node.js diff script you can run locally.