October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Compare Puppeteer Screenshots with Pixelmatch

A practical Node.js workflow for capturing Puppeteer screenshots, comparing PNG pixels with Pixelmatch, and investigating visual test failures.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Capture the same page state twice with Puppeteer, decode both PNGs with pngjs, and pass their pixel buffers to Pixelmatch. Check that the images have identical dimensions first; then decide whether the returned mismatch count should fail your test and save a diff image to help diagnose failures.

What the comparison does

Puppeteer captures the rendered page; Pixelmatch compares the decoded image data. Pixelmatch does not launch a browser or capture a page, so the workflow has three distinct parts: create an approved baseline, capture the current page in the same conditions, and compare the resulting PNGs.

As an Amazon Associate I earn from qualifying purchases.

Puppeteer’s documented page capture method is Page.screenshot(). It can capture a page or a selected element. Pixelmatch takes two pixel arrays, a same-size output array, and the shared width and height. Its return value is the number of pixels it classifies as mismatched.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install the packages and prepare a baseline

The example below uses Node.js ES modules, Puppeteer, Pixelmatch, and pngjs. Install the dependencies in your project:

#1 Best Overall
Sale
Logitech Brio 101 Full HD 1080p Webcam for Streaming and Meetings - Black | 1080p with auto-light correction, built-in mic, privacy shutter, USB-A, compatible with Teams, Google Meet, Zoom and more
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • Auto-Light Balance: RightLight boosts brightness by up to 50%, reducing shadows so you look your best—compared to previous-generation Logitech webcams (1)
  • Privacy with a Slide: The integrated webcam cover makes it easy to get total, reliable privacy when you're not on a video call
  • Built-In Mic: The built-in microphone lets others hear you clearly during video calls
  • Easy Plug-And-Play: The Brio 101 works with most video calling platforms, including Microsoft Teams, Zoom and Google Meet—no hassle; it just works
npm install puppeteer pixelmatch pngjs

Create a baseline image from a page state you have reviewed and approved. Save it as baseline.png in the project directory. The baseline and later capture must use the same viewport, capture scope, and relevant screenshot options. If your project already has a reliable baseline-generation step, keep using it rather than silently replacing an approved image during each test.

Capture and compare screenshots

Save the following as compare.mjs. It navigates to the URL in TEST_URL, writes the current screenshot to actual.png, checks image dimensions, writes diff.png, and fails if the mismatch count exceeds the configured allowance.

import fs from 'node:fs';
import puppeteer from 'puppeteer';
import { PNG } from 'pngjs';
import pixelmatch from 'pixelmatch';

const url = process.env.TEST_URL;
if (!url) {
  throw new Error('Set TEST_URL to the page you want to capture');
}

const browser = await puppeteer.launch({ headless: true });
try {
  const page = await browser.newPage({
    viewport: { width: 1280, height: 800 },
    deviceScaleFactor: 1
  });

  await page.goto(url, { waitUntil: 'networkidle2' });
  await page.screenshot({ path: 'actual.png', type: 'png' });
} finally {
  await browser.close();
}

const before = PNG.sync.read(fs.readFileSync('baseline.png'));
const after = PNG.sync.read(fs.readFileSync('actual.png'));

if (before.width !== after.width || before.height !== after.height) {
  throw new Error(
    `Screenshot dimensions differ: baseline ${before.width}x${before.height}, ` +
    `actual ${after.width}x${after.height}`
  );
}

const { width, height } = before;
const diff = new PNG({ width, height });
const mismatched = pixelmatch(
  before.data,
  after.data,
  diff.data,
  width,
  height,
  { threshold: 0.1 }
);

fs.writeFileSync('diff.png', PNG.sync.write(diff));
console.log(`${mismatched} mismatched pixels`);

const allowedMismatches = 0;
if (mismatched > allowedMismatches) {
  throw new Error(
    `Visual comparison failed: ${mismatched} mismatched pixels ` +
    `(allowance: ${allowedMismatches})`
  );
}

Run it with a URL appropriate for your test environment:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Logitech C270 720p Webcam Plug-and-Play Wide Screen Video Calling - Black | Auto-Light Correct, Noise-Reducing Mic, Zoom, Microsoft, Teams, Skype, Nintendo Switch 2 New GameChat Mode, PC Mac compatible
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • Crisp HD 720p/30 fps video calls with diagonal 55° field of view and auto light correction. Compatible with popular platforms including Skype and Zoom.
  • The built-in noise-reducing mic makes sure your voice comes across clearly up to 1.5 meters away, even if you’re in busy surroundings.
  • C270’s RightLight 2 feature adjusts to lighting conditions, producing brighter, contrasted images to help you look good in all your conference calls.
  • The adjustable universal clip lets you attach the camera securely to your screen or laptop, or fold the clip and set the webcam on a shelf. You’re always ready for your next video call.
TEST_URL=https://example.com node compare.mjs

This is an adaptable example, not a claim of a test run. Use a stable test URL and a baseline generated for that same page state. The script saves the actual image and diff before applying the mismatch policy, so those artifacts remain available when comparison fails.

Make capture conditions repeatable

Wait for the state you intend to test

The example uses waitUntil: 'networkidle2', a navigation option shown in Puppeteer’s screenshot guidance. Network quiet does not prove that an application has finished rendering: content can load later, animations can continue, and data can change independently of network activity. If the page has a meaningful ready condition, wait for that selector or application state before taking the screenshot. Avoid arbitrary sleeps when a deterministic condition is available.

Keep the capture scope and viewport consistent

The default screenshot is a viewport capture. Puppeteer’s screenshot options also support full-page capture with fullPage: true, clipping, a file path, and background transparency. Use the same mode and options for baseline and actual images. A viewport screenshot and a full-page screenshot will not have interchangeable dimensions.

Rank #3
Sale
NexiGo N60 1080P Webcam with Microphone, Software Control & Privacy Cover, USB HD Computer Web Camera, Plug and Play, for Zoom/Skype/Teams, Conferencing and Video Calling
  • 【Full HD 1080P Webcam】Powered by a 1080p FHD two-MP CMOS, the NexiGo N60 Webcam produces exceptionally sharp and clear videos at resolutions up to 1920 x 1080 with 30fps. The 3.6mm glass lens provides a crisp image at fixed distances and is optimized between 19.6 inches to 13 feet, making it ideal for almost any indoor use.
  • 【Wide Compatibility】Works with USB 2.0/3.0, no additional drivers required. Ready to use in approximately one minute or less on any compatible device. Compatible with Mac OS X 10.7 and higher / Windows 7, 8, 10 & 11 / Android 4.0 or higher / Linux 2.6.24 / Chrome OS 29.0.1547 / Ubuntu Version 10.04 or above. Not compatible with XBOX/PS4/PS5.
  • 【Built-in Noise-Cancelling Microphone】The built-in noise-canceling microphone reduces ambient noise to enhance the sound quality of your video. Great for Zoom / Facetime / Video Calling / OBS / Twitch / Facebook / YouTube / Conferencing / Gaming / Streaming / Recording / Online School.
  • 【USB Webcam with Privacy Protection Cover】The privacy cover blocks the lens when the webcam is not in use. It's perfect to help provide security and peace of mind to anyone, from individuals to large companies. 【Note:】Please contact our support for firmware update if you have noticed any audio delays.
  • 【Wide Compatibility】Works with USB 2.0/3.0, no additional drivers required. Ready to use in approximately one minute or less on any compatible device. Compatible with Mac OS X 10.7 and higher / Windows 7, 10 & 11, Pro / Android 4.0 or higher / Linux 2.6.24 / Chrome OS 29.0.1547 / Ubuntu Version 10.04 or above. Not compatible with XBOX/PS4/PS5.

For a full-page capture, change the capture line to await page.screenshot({ path: 'actual.png', type: 'png', fullPage: true });. For an element capture, use Puppeteer’s element screenshot API and ensure the baseline was captured from the same element and page state. Pixelmatch still requires the final decoded images to have equal dimensions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Control sources of variation

For useful comparisons, keep the browser/runtime, viewport, fonts, test data, and page state consistent where practical. Disable or complete animations if they make the intended state nondeterministic. These are test-design recommendations, not a guarantee that Puppeteer produces identical output across machines. If a diff appears unexpectedly, inspect the actual screenshot before increasing tolerance.

Choose Pixelmatch options and a pass policy

threshold: sensitivity to color differences

threshold ranges from 0 to 1; Pixelmatch documents a default of 0.1. Smaller values make the comparison more sensitive. The example sets that documented default explicitly so the policy is visible in the test. It is not a universally correct setting: begin with a strict value when exact rendering is expected, then adjust only after identifying stable rendering variation that the test should ignore.

Rank #4
Sale
EMEET C960 1080P Webcam with Microphone, 2 Mics, 90° FOV, Computer Camera | USB Type-A & A-to-C Adapter, Fixed Focus, Plug&Play for Zoom/Teams/Facetime/YouTube/Google Meet/Switch 2 Camera, 2025 Version
  • 1080P Webcam with Cover for Video Calls - EMEET computer webcam provides design and Optimization for professional video streaming. Realistic 1920 x 1080p video, 5-layer anti-glare lens, providing smooth video. C960 computer camera delivers 1920x1080 video with fixed focus (11.8–118.1 inches), so as to provide a clearer image. C960 USB webcam has a cover and can be removed automatically to meet your needs for privacy. For optimal image performance, use the webcam in a well-lit environment.
  • Built-in 2 Omnidirectional Mics - EMEET webcam with microphone for desktop features 2 built-in omnidirectional microphones, picking up your voice to create clear audio for communication. When installing the webcam, select EMEET C960 as the default microphone input device in your computer and video applications and select C960 as the default device in Zoom/Teams and ensure microphone permissions are enabled for proper use. Please note that C960 does not include built-in speakers.
  • Automatic Light Adjustment - Automatic exposure adjustment is applied in EMEET HD webcam 1080p so that the streaming webcam can deliver stable image performance. EMEET C960 camera for computer also features color adjustment and exposure optimization to help you look your best. For optimal video quality, it is recommended to use the webcam in normal or well-lit environments and select suitable video settings in your application. Proper lighting helps achieve a clearer and more balanced image.
  • Plug-and-Play & Upgraded USB Connectivity - New C960 webcam features both USB Type-A & A-to-C adapter connections for wider compatibility. For stable performance, connect the webcam directly to the computer's main USB port and ensure the device is recognized correctly. If a hub or docking station is used, please ensure it provides sufficient power and stable data transmission, as limited ports may affect performance. 90° wide-angle lens captures more participants without frequent adjustments.
  • High Compatibility & Multi Application - C960 webcam for laptop is compatible with Windows 10/11, macOS 10.14+, and Android TV 7.0+. Not supported: Windows Hello, TVs, tablets, or game consoles. It works with Zoom, Teams, Facetime, Google Meet, YouTube and more. Please select C960 webcam as the default camera and microphone device in your application and ensure camera/microphone permissions are enabled, especially on macOS. (Tips: Incompatible with Windows Hello)

includeAA: whether anti-aliased edge pixels count

Pixelmatch defaults includeAA to false, which enables its anti-alias detection and ignoring behavior. Set it to true to disable that behavior, which can make more edge pixels count as differences. Choose based on whether the visual changes your team needs to catch are being obscured or whether edge noise is creating unwanted failures.

Diff appearance options

diffColor, diffColorAlt, aaColor, and diffMask affect how the output diff is displayed. They help people inspect a change; they do not replace a pass/fail policy. Keep the saved baseline, actual, and diff together when a test fails so reviewers can distinguish a meaningful regression from capture variation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Global mismatch count or localized window count

By default, Pixelmatch returns the total number of differing pixels. With windowSize: N, it instead reports the maximum count in any sliding N-by-N pixel window. That alternative can make scattered GPU dithering or subpixel anti-aliasing noise less prominent than a compact change. Because it measures a local maximum rather than the global total, document the chosen window size and set an allowance that matches that measurement.

Best Value
Logitech C920x HD Pro PC Webcam Full 1080p/30fps Video - Black | 30fps Video, Clear Audio, Light Correction, Works with Teams, Meet, Zoom, Nintendo Switch 2, Mac, Tablet
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • HD lighting adjustment and autofocus: The Logitech webcam automatically fine-tunes the lighting, producing bright, razor-sharp images even in low-light settings. This makes it a great webcam for streaming and an ideal web camera for laptop use
  • Advanced capture software: Easily create and share video content with this Logitech camera that is suitable for use as a desktop computer camera or a monitor webcam
  • Stereo audio with dual mics: Capture natural sound during calls and recorded videos with this 1080p webcam, great as a video conference camera or a computer webcam
  • Full HD 1080p video calling and recording at 30 fps. You'll make a strong impression with this PC webcam that features crisp, clearly detailed, and vibrantly colored video

Set an allowance deliberately

The example fails on any mismatch. That strict policy is useful only when the rendering environment and page state are stable enough to support it. There is no universal allowance established by the cited package documentation. If you choose a nonzero allowance, record why, review representative failures, and avoid treating a large count as harmless just because it is below a convenient number.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common comparison failures

  • Different image dimensions: Pixelmatch requires equal input dimensions. Check viewport, device scale factor, full-page versus viewport mode, clipping, and element bounds; regenerate the baseline only if the intended capture contract has changed.
  • Too many mismatches on every run: Compare actual.png with the baseline and check page state, test data, fonts, browser/runtime, and screenshot settings. Do not start by loosening threshold; first find what changed.
  • Intermittent diffs: A page may still be rendering, contain animation, or depend on changing data. Replace a generic wait with an application-specific ready condition where possible, and stabilize the test inputs.
  • Diff image is missing or unreadable: Confirm the comparison reached the write step and that the decoded images have matching dimensions. The output PNG must use the same width and height as the input images.
  • Import or package errors: The sample uses ES module syntax in a .mjs file. Install all three dependencies in the project and run it with Node.js; if using CommonJS, adapt the imports consistently rather than mixing module systems.
  • The test reports a failure but the page looks unchanged: Inspect baseline.png, actual.png, and diff.png together. Consider whether anti-aliased edges or scattered renderer noise explain the count, then make any option or allowance change explicit in the test policy.

Or skip the browser setup

For a one-request screenshot rather than a local Puppeteer-and-Pixelmatch pipeline, ScreenshotNeo is a website screenshot API and MCP server. Its clean-shot processing accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for AI agents.

Use the [ScreenshotNeo API documentation] for request options. This cURL example saves the response as a WebP image:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo offers 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.