Use a pixel-difference assertion against an approved baseline, with two separate tolerances: a per-pixel color threshold and a maximum number or ratio of differing pixels. These settings can absorb small rendering variations, but they do not realign elements that moved. If meaningful UI shifts, inspect the diff and let the test fail rather than raising the tolerance until it passes.
What the two pixel tolerances actually control
Playwright Test’s toHaveScreenshot() compares a new screenshot with a stored reference image. On its first run, it creates the reference; later runs compare against it. Playwright waits for two consecutive screenshots to match before saving an initial image. See Playwright’s visual comparisons documentation.
As an Amazon Associate I earn from qualifying purchases.
| Setting | What it controls | How to think about it |
|---|---|---|
threshold |
How much perceived color difference is allowed at an individual corresponding pixel. The API documents a range from 0 (strict) to 1 (lax), with 0.2 as the default. | Pixel sensitivity: whether a pixel counts as changed. |
maxDiffPixels |
The maximum absolute number of pixels allowed to differ. | Total changed-pixel budget. |
maxDiffPixelRatio |
The maximum fraction of image pixels allowed to differ. | Total changed-pixel budget expressed as a ratio. |
The maximum-difference settings are unset unless you configure them. threshold does not mean “allow this percentage of the page to change”; it governs color difference at a pixel. The count or ratio sets the overall budget. Consult the current SnapshotAssertions API reference for details and support in your installed Playwright version.
Why thresholds do not automatically ignore layout shifts
Playwright’s screenshot comparison is pixel-based. The threshold assesses corresponding pixels; the maximum-difference settings limit how many pixels can differ. Neither is documented as a translation-invariant comparison that searches for an element after it moves.
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
A small movement of a button or card can change pixels both where it used to be and where it moved to. A permissive total budget may allow that real regression through. Pixel tolerances are useful for minor rendering noise, not as a substitute for correcting capture instability or reviewing an unintended layout change.
Set up a repeatable Playwright comparison
1. Capture the same page state
Fix the viewport, browser project, fonts, and test data, then wait for the page state your test is meant to verify. Screenshot assertions disable animations by default and wait for two consecutive matching captures, but external data, delayed content, and other changing page state can still make captures unstable.
Playwright warns that rendering can vary with the host operating system, browser version, settings, hardware, power source, headless mode, and other factors. Generate and compare baselines in the same environment when possible. If you validate separate browsers or platforms, keep the corresponding baselines separate; Playwright’s visual comparison guidance describes snapshot naming by browser and platform.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
2. Start with per-pixel sensitivity
Use the documented default, threshold: 0.2, as a starting point, not a universal answer. Lower values are stricter; higher values are more tolerant. The right value depends on how consistent your rendering environment is and which visual changes matter to your product.
3. Add only a measured total-difference budget
If repeatable captures still have a small, understood amount of harmless noise, allow a limited number of differing pixels with maxDiffPixels or a limited fraction with maxDiffPixelRatio. Change one tolerance at a time and inspect the resulting diff. Do not raise a budget simply to make an unexplained failure pass.
4. Keep the tested area honest
Use mask for a genuinely volatile locator, such as a timestamp, or use stylePath to hide or normalize known changing content. Prefer deterministic test data when practical. A masked region is no longer being tested, so do not mask content whose position or appearance is part of the behavior you need to protect.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Choose the screenshot scope deliberately: viewport, fullPage, a clip, or a focused element capture. Clipping and masking change which pixels participate in the comparison.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, 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 minute5. Review changes before updating the baseline
Keep reference snapshots in version control and review visual diffs. Update them only after confirming that the change is intended. Playwright documents snapshot update workflows in its visual comparisons guide.
Runnable Playwright Test example
This example captures a named page screenshot, tolerates a small configured difference budget, and masks a known timestamp. Replace the URL, locator, and budgets with values appropriate to your test. The options shown are documented by Playwright; PNG is the default snapshot format.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
import { test, expect } from '@playwright/test';
test('product page matches its visual baseline', async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 });
await page.goto('https://example.com/product');
await page.getByRole('heading', { name: 'Product details' }).waitFor();
await expect(page).toHaveScreenshot('product-page.png', {
threshold: 0.2,
maxDiffPixelRatio: 0.001,
animations: 'disabled',
mask: [page.locator('[data-testid="updated-at"]')],
});
});
The first run creates the reference image; inspect and commit that reference before relying on later comparisons. Subsequent runs assert against it. Use maxDiffPixels instead when an absolute pixel budget is easier to reason about than a percentage. Other relevant options include maskColor, stylePath, fullPage, clip, and scale; check the API reference for the installed version.
Troubleshoot screenshot comparison failures
- Fails on a machine but passes locally: rendering environments may differ. Align OS, browser version, settings, headless mode, fonts, and other capture conditions, or maintain separate baselines for distinct browser/platform projects.
- Fails intermittently: find the unstable page state, such as delayed data or changing content. Wait for the relevant state or make the data deterministic; mask only a region that is intentionally outside the test’s scope.
- Too many changed pixels after a small movement: that can be the expected result of a pixelwise comparison. Inspect the diff and determine whether the movement is intended. Do not assume a higher area budget will distinguish harmless movement from a regression.
- Mask hides an unexpected change: remove or narrow the mask if that content matters. Everything under a mask is excluded from meaningful visual review by the assertion.
- Test cannot use
toHaveScreenshot(): screenshot assertions require the Playwright Test runner. Confirm the test is running under@playwright/testand consult the API documentation for the installed version. - Baseline changed unexpectedly: do not accept it automatically. Inspect the diff, confirm the page state and capture environment, and update the reference only for an approved visual change.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server. Its screenshot endpoint takes one GET request and returns an image or PDF; the API also accepts parameter names used by other screenshot APIs. See the ScreenshotNeo API documentation.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Frequently Asked Questions
Does Playwright’s threshold set the percentage of pixels allowed to change?
No. It sets per-pixel color sensitivity; maxDiffPixels or maxDiffPixelRatio sets the total changed-pixel budget.
What is Playwright’s default screenshot threshold?
The SnapshotAssertions API documents threshold: 0.2 by default. The maximum differing-pixel count and ratio are not set by default.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsQuick 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.




