Skip to content

Full-page screenshot: scroll in CSS pixels and slot each shot to one viewport (phone fix) - #63

Merged
woutervanwijk merged 1 commit into
mainfrom
claude/full-page-screenshot-phone-fix
Nov 19, 2026
Merged

woutervanwijk merged 1 commit into
mainfrom
claude/full-page-screenshot-phone-fix

Conversation

@woutervanwijk

Copy link
Copy Markdown
Owner

Problem

On phones (devicePixelRatio > 1) the full-page screenshot behind the Structure tab wireframe was misaligned from the second viewport on: the first screenful was fine, later ones appeared shifted and much larger than they should be. Desktop (DPR 1) was unaffected.

Cause

  • The capture scrolled with the native scrollTo(x, y), which works in view/physical pixels. On a phone each "one viewport" step advanced only vh/DPR CSS pixels, so shots after the first were taken at the wrong offsets.
  • The stitcher drew each shot at its natural pixel height, so a shot decoding at an unexpected size would occupy an oversized segment.

Fix

  • html_service.dart: new _scrollPageTo scrolls via JavaScript in an isolated world — window.scrollTo({top: y, behavior: "instant"}) (CSS pixels, immune to page-level scroll-behavior: smooth) — and polls window.scrollY until the scroll settles. The capture loop and the restore use it; the real scroll offset is still recorded per shot. Dimensions are read in the same isolated world.
  • screenshot_stitch.dart: stitchScreenshots takes viewportHeight and draws every shot into a slot of exactly one viewport (viewportHeight × scale) at its recorded offset — segments are uniform by construction, odd-sized shots get squeezed instead of enlarging their segment.

Verification

  • flutter analyze clean; flutter test 1685 pass.
  • New regression test: a shot decoding 50% taller than a viewport is squeezed into its slot and the stitched image stays exactly page-height. Existing offset/clamping/scaling stitch tests updated for the new parameter.

…viewport

On phones (devicePixelRatio > 1) the native scrollTo works in view pixels,
so each capture step advanced only a fraction of a viewport and the shots
after the first landed misaligned and oversized in the stitched image.
Scroll via JavaScript in an isolated world with instant behavior and wait
for scrollY to settle; record the real offset per shot as before. In the
stitcher, draw every shot into a slot of exactly one viewport height at the
shot scale, so an odd-sized shot cannot enlarge its segment.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@woutervanwijk
woutervanwijk merged commit 5121cd9 into main Nov 19, 2026
1 check passed
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