Skip to content

feat(puppeteer): support the blackout helper and add mask option - #404

Merged
gregberge merged 1 commit into
greg/arg-520-ignore-regions-in-screenshot-comparisonsfrom
greg/puppeteer-mask
Oct 21, 2026
Merged

gregberge merged 1 commit into
greg/arg-520-ignore-regions-in-screenshot-comparisonsfrom
greg/puppeteer-mask

Conversation

@gregberge

Copy link
Copy Markdown
Member

Stacked on #403 (ARG-520).

Why

Puppeteer has no native mask, so [data-visual-test="blackout"] was silently ignored by @argos-ci/puppeteer (the docs say blackout is "Storybook, Playwright, and Cypress SDKs only"). Playwright has mask and Cypress has blackout; Puppeteer had nothing.

What

  • @argos-ci/browser: new __ARGOS__.mask(elements, color), undone by afterEach(). It draws a box over each element, the way Playwright's own mask works:
    • a glass pane shown as a popover="manual" so it sits in the top layer, above modal dialogs and popovers;
    • boxes inside a shadow root, so page styles don't reach them, positioned from getBoundingClientRect();
    • a requestAnimationFrame loop that keeps the boxes on their elements until cleanup. Puppeteer scrolls the element into view inside ElementHandle.screenshot(), after we measure, and resizes the viewport for fullPage + captureBeyondViewport: false.
  • @argos-ci/puppeteer: new mask option ((string | ElementHandle)[]) and maskColor option (default #FF00FF, same as Playwright and the WebdriverIO SDK). [data-visual-test="blackout"] is always masked. The mask is applied after the last stabilization wait, right before capture, so the boxes match the final layout.

The browser function is generic, so other SDKs without a native mask can reuse it.

Tests

Pixel-level tests in packages/puppeteer/test.spec.js decode the PNG in the page with a canvas:

  • blackout helper + mask selectors and handles, with exact box edges, and the overlay is removed afterwards;
  • maskColor;
  • full-page screenshot of a page scrolled to 1000px, with an element masked below the fold;
  • element screenshot of an element below the fold (fails without the rAF loop);
  • element masked inside an open modal <dialog> (fails without the popover).

pnpm exec turbo run check-types lint check-format --filter=@argos-ci/puppeteer --filter=@argos-ci/browser passes, and all 17 Puppeteer tests pass locally.

Follow-ups

  • Docs: drop "Storybook, Playwright, and Cypress SDKs only" from the blackout helper and document mask/maskColor in the Puppeteer reference, once this ships.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
argos-js-sdk-reference Ready Ready Preview Oct 21, 2026 8:20am UTC

Request Review

@gregberge
gregberge force-pushed the greg/arg-520-ignore-regions-in-screenshot-comparisons branch from cd9b9f3 to 8d11d98 Compare October 21, 2026 08:16
Puppeteer has no native mask, so `[data-visual-test="blackout"]` was
silently ignored. Cover masked elements with boxes drawn by the browser
script, like Playwright does: a glass pane in the top layer (above modal
dialogs) whose boxes follow the elements until the screenshot is taken,
since Puppeteer scrolls the element into view for element screenshots.

The boxes are applied once the page is stable and removed by `afterEach`.
`mask` accepts selectors or `ElementHandle`s, and `maskColor` defaults to

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gregberge
gregberge force-pushed the greg/puppeteer-mask branch from 8ad3432 to 7d03fce Compare October 21, 2026 08:19
@gregberge
gregberge requested a review from jsfez October 21, 2026 08:52
@gregberge
gregberge merged commit 29bbd24 into greg/arg-520-ignore-regions-in-screenshot-comparisons Oct 21, 2026
2 checks passed
@gregberge
gregberge deleted the greg/puppeteer-mask branch October 21, 2026 08:58

This branch was successfully deployed

1 active deployment
Preview — 7d03fcea Deployed Oct 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant