-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
🚀 Feature Request
Overview
Currently, the mask option in Playwright allows users to overlay elements with a solid color during snapshot comparison. However, snapshot comparisons still include the masked elements, leading to test failures if those elements change.
This feature request proposes an enhancement to allow users to both mask and ignore elements
during snapshot comparison. The goal is to:
Mask elements with an overlay color
so users can see what’s behind them.Ignore changes in masked elements
to prevent test failures due to dynamic content.
Current Implementation Limitation
Consider the following example:
const maskElements = [landingPagePo.elm1(), landingPagePo.elm2(), landingPagePo.elm3()];
await expect(page).toHaveScreenshot("snapshot1.png", {
fullPage: true,
mask: maskElements,
maskColor: maskOverlay
});
Here, maskOverlay is defined in the fixtures file as:
maskOverlay: async ({}, use) => {
await use("rgb(118, 232, 255)");
},
By default, the mask color is 100% pink
, making it impossible to see what’s behind the masked elements. Setting a custom maskOverlay
resolves this issue, but masked elements are still compared in the snapshot, causing test failures if they change.
Proposed Enhancement
To fully support both use cases, Playwright should introduce a new option that allows:
- Masking elements with an overlay color (similar to the current mask option).
- Ignoring those elements in snapshot comparison to prevent test failures.
One potential approach is to introduce a concept similar to Applitools' ignored elements with padding (reference), which would:
- Allow users to mask/ignore elements while still displaying an overlay.
- Prevent snapshot comparisons from failing due to changes in ignored elements.
Suggested Implementation
- Keep the mask option unchanged for users who only want visual masking.
- Introduce a new ignore option that:
- Hides selected elements from comparison.
- Allows setting custom padding (instead of a fixed default).
- Supports an overlay color (or an alternative visualization method).
This enhancement would provide better control over masked elements and improve snapshot testing reliability for dynamic UI components.
Example
User select one or more element to be ignored with extra padding. Something like this when feature is introduce,
const ignoredElements = [landingPagePo.elm1(), landingPagePo.elm2(), landingPagePo.elm3()];
await expect(page).toHaveScreenshot("snapshot1.png", {
fullPage: true,
ignore: ignoredElements, // this is the feature requesting
padding = { top: 5, bottom: 5, left: 20, right: 20 } // default 0 if not added and can be configured via config or fixtures
maskColor: maskOverlay // can be used in both mask and ignored
});
Motivation
This enhancement would provide better control over masked elements and improve snapshot testing reliability for dynamic UI components. It ensures that snapshots retain full clarity, even for ignored or masked elements, allowing users to see what’s behind them while preventing unnecessary test failures due to expected
UI changes.
By introducing an "ignore" option with padding support, users can selectively exclude elements from snapshot comparisons while still applying an overlay color for visibility. This would reduce noise in test failures caused by dynamic elements and improve the accuracy of visual regression testing.
Activity
mxschmitt commentedon Mar 26, 2025
For that we provide the
stylePath
option, see here to learn more about it: https://playwright.dev/docs/test-snapshots#stylepathThis should allow you to entirely hide elements from your page. You can e.g. annotate them before with custom DOM attributes or just put their selectors inside.
Would that work for you?
aaravbinit commentedon Mar 26, 2025
Thank you for the response! However, the
stylePath
option does not achieve the intended goal.The requirement is not to completely hide elements but to exclude them from snapshot comparison while keeping them visible.
For example, in the attached image (similar to Applitools behavior), the ignored elements are still visible but do not trigger test failures if their content changes.

This is crucial for:
Current Issue with maskOverlay:
Using maskOverlay, I can apply a
color overlay with lower opacity
:However, if the text inside the masked elements changes, the test still fails. See this image for example. On the left side I have 100% pink color masked elements. Now whan i changed the
mask color with lower opacity
, it failed (on the right side)Why This Feature is Needed:
Proposed enhancement:
Would it be possible to introduce an ignore option that preserves visibility while excluding elements from comparison? This would provide more flexibility and reduce noise in visual testing.
Thanks for considering this request! Let me know if more details are needed.
aaravbinit commentedon Jun 16, 2025
Hello @mxschmitt
I noticed that the feature request I submitted was initially tagged for an upcoming release, but has since been moved out of the latest version. I see that it hasn’t been closed, which is encouraging.
Do we know if this feature is expected to be included in an upcoming release or if it's been scheduled for a specific future version?
Also, please let me know if any further clarification is needed from my side to help move it forward.
Thanks again for your time and support!