Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#42959·Playwright

[Docs]: maxDiffPixels: 0 is not an exact comparison — say that threshold still applies

Author: neupenguinCreated Sep 28, 2026Updated Sep 28, 2026

Page(s)

  • https://playwright.dev/docs/next/api/class-locatorassertions (toHaveScreenshot, maxDiffPixels and maxDiffPixelRatio options)
  • https://playwright.dev/docs/next/api/class-pageassertions (same options)
  • https://playwright.dev/docs/next/test-snapshots
  • Source: docs/src/api/params.md, ## assertions-max-diff-pixels and ## assertions-max-diff-pixel-ratio

Description

expect(locator).toHaveScreenshot(name[, options]) and expect(page).toHaveScreenshot(name[, options])

The maxDiffPixels entry reads "An acceptable amount of pixels that could be different." That makes maxDiffPixels: 0 read like an exact comparison. It is not: a pixel only counts as different once its colour moves by more than threshold, which defaults to 0.2. So with maxDiffPixels: 0 alone, every pixel may still drift by up to 0.2 in YIQ distance and the assertion passes.

At 0.2 that is enough to hide real changes. In our suite a faint card border read as the background behind it: a baseline passed against a build with the fix reverted, and failed with 1317 px once threshold was set to 0.1. A second case: two text colours (#454039 and #6e6860) compared equal at the default. Our config set maxDiffPixels: 0 and described it in a comment as "zero tolerance".

The threshold entry is accurate; the trap is that nothing in the maxDiffPixels or maxDiffPixelRatio entries says the two work together. Suggested addition to both:

A pixel counts as different only when its colour differs by more than threshold (default 0.2), so maxDiffPixels: 0 does not make the comparison exact. Set threshold too for a stricter comparison.

A sentence to the same effect in the "Visual comparisons" guide, near the maxDiffPixels example, would help as well, since that is where most configs are copied from.

Source: microsoft/playwright

View original on GitHubView discussion on GitHub