[fix]: screenshot mask not working on `<dialog>` elements
Merged
SE
10mo ago+238+238+012345678901234567890123456789-31-31-01234567890123456789
why
- top‑layer UI (like
<dialog>and popovers) is painted above the normal document stacking context, so a mask appended todocument.bodycan never cover it. in order to mask dialog content, the overlay must be inserted inside the top‑layer container itself - the screenshot masking logic for elements inside
<dialog>nodes (and other top‑layer elements) didn’t work because the overlay divs were always appended to the document root, which renders underneath the dialog - this PR addresses #1616
what changed
- updated logic in
resolveMaskRect()to detect top‑layer roots (dialog[open], :popover-open), compute rects relative to that root, and return arootTokenso the caller can target the correct container - updated
applyMaskOverlays()to insert mask overlays inside the top‑layer root when arootTokenis present, and to restore any temporary position changes on cleanup.resolveMaskRectForObject()now passes amaskTokenand preserves therootTokenoutput
test plan
- added another test in
page-screenshot.spec.tsto check whether masks are correctly injected into the dialog node
Summary by cubic
Fixes screenshot masking for elements inside dialog and other top‑layer UIs by inserting overlays into the top‑layer root instead of the document root. Masks now correctly cover dialogs and are fully cleaned up after the screenshot.
- Bug Fixes
- Detect top‑layer roots (dialog[open], :popover-open) in resolveMaskRect, compute rects relative to that root, and return a rootToken.
- Insert mask overlays inside the detected top‑layer container; temporarily adjust position when needed and restore on cleanup.
- Thread a maskToken/rootToken through masking calls to group overlays and handle multi-frame cases safely.
- Add a test to confirm masks are injected into dialog elements.