To compare Puppeteer screenshots with Pixelmatch, capture the baseline and current page as PNGs, decode them with pngjs, and pass their pixel data to pixelmatch. The images must have the same dimensions. Pixelmatch returns a differing-pixel count and can write a visual diff image; your test decides how many mismatches are acceptable.
How the comparison works
Puppeteer renders and captures each page state; Pixelmatch compares the resulting pixel arrays. The basic pipeline is:
- Capture the approved baseline and the current page in a repeatable browser state.
- Decode both PNG files with
pngjs. - Confirm that their widths and heights match.
- Compare the pixel data with Pixelmatch, save a diff image if useful, and apply your test’s mismatch policy.
Puppeteer’s documented capture method is Page.screenshot(), and it also supports screenshots of selected elements. Puppeteer’s screenshots guide shows navigation with waitUntil: 'networkidle2' before capture. Network idle is only one possible wait condition: it does not guarantee that application data, animations, or other visual changes have settled.
Install the packages
In a Node.js project, install Puppeteer, Pixelmatch, and pngjs:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minute#1 Best Overall
- 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
The example below uses ES modules. To run it as written, set "type": "module" in your project’s package.json, or save it as an .mjs file. Puppeteer’s current documentation was version 25.12.0 on October 3, 2026; Pixelmatch’s npm listing showed version 7.2.0 on that date. Check the package documentation for current versions and API details before changing dependencies.
Capture comparable screenshots with Puppeteer
Use the same browser setup, viewport, capture scope, and screenshot options for both states. The following script saves a baseline and an actual screenshot of the same URL at a fixed viewport. Adapt the URL and navigation or readiness condition to your application.
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
try {
const page = await browser.newPage({
viewport: { width: 1365, height: 900 },
deviceScaleFactor: 1,
});
await page.goto('https://example.com', { waitUntil: 'networkidle2' });
// Replace this with an application-specific readiness check if needed.
await page.screenshot({ path: 'baseline.png', fullPage: true });
// In a real test, put the page into the state being checked before this capture.
await page.screenshot({ path: 'actual.png', fullPage: true });
} finally {
await browser.close();
}
This is a runnable capture pattern, but it intentionally captures the same page twice. A real visual regression test must arrange for the first capture to be the approved reference and the second capture to reflect the current build or state. Store the baseline as a reviewed test artifact rather than regenerating it automatically whenever a test fails.
Rank #2
- 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.
Choose the capture scope deliberately
- Viewport: captures the visible browser area. This is the default scope when
fullPageis not enabled. - Full page: set
fullPage: trueto capture beyond the viewport. Pages with lazy-loaded content may need an application-specific scroll or readiness step so that content is present before the capture. - Element: use Puppeteer’s element screenshot capability when only a component matters. Keep the selected element and resulting image dimensions consistent between baseline and actual.
- Clip: screenshot options can capture a specified rectangle. Use identical clip coordinates and dimensions in both runs.
Puppeteer screenshot options also include a file path and background transparency. For all capture modes, keep options aligned between the reference and current image. See the Puppeteer screenshot options for the documented controls.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Compare the PNGs and save a Pixelmatch diff
Save this as compare.js in the ES-module project above, after creating baseline.png and actual.png. It checks dimensions, writes diff.png, and fails when any pixel differs.
import fs from 'node:fs';
import { PNG } from 'pngjs';
import pixelmatch from 'pixelmatch';
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: ${before.width}x${before.height} vs ` +
`${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} pixels differ`);
if (mismatched > 0) {
throw new Error(`${mismatched} pixels differ`);
}
Pixelmatch requires equal input dimensions, and the output image buffer must have those dimensions too. PNG.sync.read decodes PNG data into pixel arrays; PNG.sync.write encodes the diff buffer back into a PNG. Pixelmatch’s returned value is the mismatch count, not a percentage.
Rank #3
- 【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.
Set a mismatch policy that fits the test
A zero-difference rule is simple and strict, as in the example. It can also fail on small rendering variations that do not represent a meaningful regression. There is no universally correct allowance in the cited documentation: choose and document a policy for your application, and inspect representative failures before relaxing it.
Threshold and anti-aliasing
thresholdranges from 0 to 1; Pixelmatch documents a default of0.1. A smaller threshold makes the comparison more sensitive. Treat the default as API behavior, not as a universally suitable test setting.includeAAdefaults tofalse. Setting it totruedisables Pixelmatch’s anti-alias detection and ignoring behavior, so more edge pixels may count as differences. Decide based on whether the edge artifacts in your output are noise or a meaningful change.
Diff appearance and localized changes
diffColor, diffColorAlt, aaColor, and diffMask adjust how the output diff is rendered; they do not set the test’s pass/fail policy. By default, Pixelmatch reports the total number of differing pixels. With windowSize: N, it instead reports the maximum difference count in any sliding N-by-N pixel window. This can make a compact change easier to distinguish from scattered renderer noise, but it is a different measurement. Document the window size and interpret the resulting count accordingly.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteMake captures repeatable
When a comparison changes unexpectedly, first check that the capture itself is equivalent. A pixel comparison cannot tell whether a difference came from a product change or from a different capture setup.
Rank #4
- 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)
- Use the same viewport, device scale factor, full-page or element mode, clip, and background settings.
- Wait for an application-specific ready condition where possible. Network idle alone may not mean that the visible state is stable.
- Keep test data and page state consistent. Consider controlling animations and using the same browser/runtime and fonts across runs as practical safeguards; these are test-design recommendations, not guarantees of deterministic output.
- When a test fails, retain the baseline, actual image, and diff so a reviewer can inspect the change rather than relying only on a count.
Troubleshooting common comparison failures
“Screenshot dimensions differ”
Pixelmatch cannot compare differently sized images. Check viewport and device scale factor, whether both captures use full-page mode, the selected element, clip bounds, and any page content that changes the full-page height. Correct the capture mismatch rather than resizing images blindly, since resizing can alter the pixels being tested.
The test reports many differences after a small page change
Open diff.png and compare it with both inputs. Verify that the page reached the intended state and that viewport, fonts, browser/runtime, and test data are consistent. If the remaining variation is stable renderer noise, consider adjusting threshold or anti-alias handling based on observed failures; do not raise tolerance without reviewing what it hides.
The full-page screenshot omits content
Some content is loaded only after scrolling or after an application-specific event. Ensure the content is present before capturing; fullPage: true selects the capture extent but does not itself prove that every lazy-loaded element has loaded.
Recommended Free Tools
Best Value
- 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
The diff image is missing or invalid
Confirm that the script reaches PNG.sync.write and that the output buffer is created with the matched input dimensions. Keep the baseline and actual files as PNGs for this pngjs decoding workflow.
Or skip the browser setup
If you need a screenshot artifact rather than a local Puppeteer comparison, ScreenshotNeo can return a screenshot or PDF from one GET request. For example, save a WebP response with cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. Cookie banners are accepted before capture and more than 60 known consent platforms, newsletter popups, and chat widgets can be removed; each of those steps can be turned off. Bot checks, blank pages, and failed loads are not billed. ScreenshotNeo also provides an MCP server with screenshot tools for AI agents, and its Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. This API does not replace comparing a baseline with Pixelmatch when that is the test you need to run.
Sign up free for 1,000 screenshots a month with no card.
Frequently Asked Questions
Does Pixelmatch compare screenshot files directly?
No. Decode PNGs into pixel arrays first; this workflow uses pngjs.
Can Pixelmatch tell whether a difference is a bug?
No. It reports pixel differences; review the images and apply a test policy appropriate to the application.
Quick Recap
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.

