Skip to content

fix: account for scroll offsets in downscaled screenshots - #2685

Open
ddussi wants to merge 1 commit into
ChromeDevTools:mainfrom
ddussi:fix/screenshot-scroll-offset
Open

fix: account for scroll offsets in downscaled screenshots#2685
ddussi wants to merge 1 commit into
ChromeDevTools:mainfrom
ddussi:fix/screenshot-scroll-offset

Conversation

@ddussi

@ddussi ddussi commented Sep 7, 2026

Copy link
Copy Markdown

Fixes #2684

When a screenshot size limit causes downscaling, viewport and element screenshots on a scrolled page capture the wrong region because their clip coordinates omit the page scroll offset.

Summary

  • Return document coordinates from getSourceBox() by reading scroll offsets alongside the existing dimensions and device pixel ratio. Add the main page offset to element bounding boxes; keep full-page boxes at the document origin.
  • Add three browser regression tests for emulated viewports, native viewports, and element screenshots. They check captured pixels after horizontal and vertical scrolling and verify that the scroll position is preserved.

Testing

All three regressions fail against unmodified source and pass with the fix.

  • npm run test -- --test-concurrency=2: 897 passed, 3 skipped, 0 failed.
  • Screenshot tests: 23 pass, including against the bundled build.
  • npm run check-format and npm run gen: pass; no generated-file changes.
  • NODE_OPTIONS=--max_old_space_size=4096 npm run bundle and npm run test:notices:no-build: pass.

Separate clipped-capture problems with pinch zoom and RTL layouts also reproduce before this patch and are not addressed here.

@google-cla

google-cla Bot commented Sep 7, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

Downscaled screenshots capture the wrong region after scrolling

1 participant