fix(screenshot): capture beyond viewport for off-screen clips#2271
Draft
filip-michalsky wants to merge 1 commit into
Draft
fix(screenshot): capture beyond viewport for off-screen clips#2271filip-michalsky wants to merge 1 commit into
filip-michalsky wants to merge 1 commit into
Conversation
CDP Page.captureScreenshot only renders the visible viewport unless captureBeyondViewport is set. Stagehand enabled it only for fullPage, so a clip below the fold (or an element scrolled off-screen) came back blank — the "any screenshot taken beyond the viewport will turn up blank" behavior seen in STG-2335. Auto-enable captureBeyondViewport whenever a clip falls outside the current viewport (mirroring Playwright); in-viewport clips are unchanged. Adds pure helpers (clipFitsViewport / shouldCaptureBeyondViewport) with unit coverage. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 885d206 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
CDP Page.captureScreenshot only renders the visible viewport unless captureBeyondViewport is set. Stagehand enabled it only for fullPage, so a clip below the fold (or an element scrolled off-screen) came back blank — the "any screenshot taken beyond the viewport will turn up blank" behavior seen in STG-2335.
Auto-enable captureBeyondViewport whenever a clip falls outside the current viewport (mirroring Playwright); in-viewport clips are unchanged. Adds pure helpers (clipFitsViewport / shouldCaptureBeyondViewport) with unit coverage.
why
page.screenshot({ clip })returned a blank image whenever the clip fell outside the current viewport — a clip below the fold, or an element scrolled off-screen. This is the "any screenshot taken beyond the viewport will turn up blank" behavior reported in STG-2335 (PermitFlow).Root cause: CDP
Page.captureScreenshotonly renders the visible viewport unlesscaptureBeyondViewportis set. Stagehand enabled it only forfullPage, so non-fullPage clips outside the viewport rendered blank. Playwright avoids this by enablingcaptureBeyondViewportwhen the clip doesn't fit the viewport.what changed
screenshotUtils.ts: added pure helpersgetViewportMetrics,clipFitsViewport, andshouldCaptureBeyondViewport.page.ts: computescaptureBeyondViewport(true forfullPage, or any clip outside the current viewport) and passes it to the frame capture.frame.ts: honors an explicitcaptureBeyondViewport, falling back tofullPageso existing behavior is unchanged.screenshot-capture-beyond-viewport.test.ts) and a changeset.In-viewport clips are unchanged (
captureBeyondViewportstaysfalse), so no behavior change for visible clips.test plan
Unit — 10 tests covering the decision logic: in-viewport vs below-the-fold clips, scroll offset, sub-pixel tolerance, and the unmeasurable-viewport fallback.
Live Chrome repro — below-the-fold clip (
y=1449, fold at711, content height2556):captureBeyondViewport:false)page.screenshot({clip})Typecheck clean (only pre-existing
Protocol.WebMCPerrors remain).