Repository navigation
Conversation
Capture the space around an element (shadows, focus rings, overflowing content) with `padding`, a number or a CSS-shorthand array of up to 4 values. The captured area is clamped to the page, and to the frame for a Playwright `Frame` handler. - Playwright, Puppeteer: new `padding` option, requires `element`. - Cypress: the native `padding` option is now clamped to the page; Cypress shifted the area back into the page instead. - Vitest: `padding` per-call option. Playwright's `argosScreenshot` also accepts a `Locator` as handler, a shortcut for the `element` option. It used to be mistaken for a Frame and failed with an unrelated error. Fixes ARG-515 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- Validate the `padding` option once with `resolvePaddingOption`, and pass resolved sides to `getPaddedClip` and `clampPadding`. A zero padding takes the regular element screenshot path. - Measure the document with `__ARGOS__.getDocumentMetrics()` in Puppeteer and Cypress instead of a copy in each SDK. - Playwright: resolve the element once, clamp to the frame the element lives in whatever the handler, and only capture beyond the viewport when the area doesn't fit in it, like an element screenshot. - Playwright: detect frames by `parentFrame`, so a Locator is never mistaken for one. - Share test helpers instead of copy-pasted assertions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes ARG-515. Element screenshots can now capture the space around the element (shadows, focus rings, overflowing content) with a
paddingoption. Before, only Storybook could do this (fitToContent.padding); the other SDKs clipped to the element's box.paddingis a number, or an array of 1 to 4 numbers in CSS shorthand order ([10, 20],[1, 2, 3, 4]), in CSS pixels. The captured area is clamped to the page. It's namedpaddingbecause Cypress already has a native option with that name and meaning.paddingoption. It requireselementand throws if combined withclipor given an invalid value. The SDK scrolls the element into view, adds the padding to its bounding box, and takes apage.screenshotwith aclip. Like an element screenshot, it only captures beyond the viewport when the area doesn't fit in it, which is much slower on long pages in Chromium. When the element is in an iframe, the area is also clamped to that iframe's visible content, so the frame border and the page around it stay out. This holds whatever the handler.@argos-ci/vitestcaptures through an iframe, so this matters there.cliponly exists in recent versions, and the peer range is>=1, so the SDK passes an absolutecliptopage.screenshot.paddingalready reachedcy.screenshot, but Cypress doesn't clamp it: near the page edge it moves the area back inside the page. A 100px element in the corner withpadding: 20came out 140×140 with 40px of page on two sides. The SDK now reduces the padding to fit the page before calling Cypress. Screenshots of the page, not an element, still passpaddingthrough, and Cypress ignores it.paddingper-call option, forwarded to the Playwright SDK.argosScreenshot(page.getByRole("dialog"), "dialog")now works as a shortcut for theelementoption. Before, a Locator was mistaken for a Frame (both havepage()) and failed with an unrelatedaddScriptTagerror.checkIsFramenow checksparentFrame, which only frames have. The SDK resolves the locator's frame, so a locator inside an iframe is stabilized in that iframe. Passing a Locator together withelementthrows.The validation and padding math (
resolvePaddingOption,getPaddedClip,clampPadding) live in@argos-ci/util. Puppeteer and Cypress measure the document with a new__ARGOS__.getDocumentMetrics()in@argos-ci/browser.padding: 0takes the regular element screenshot path.Type of changes
enhancementChecklist
Optional checks:
paddingand PlaywrightLocatorhandler docs#272Further comments
argosScreenshot(page.getByRole("dialog"), …), which works once this ships. docs: document element screenshotpaddingand PlaywrightLocatorhandler docs#272 addspaddingto the four SDK references and should merge after the release.🤖 Generated with Claude Code