fix: respect screenshot bounds on HiDPI displays - #2536
Conversation
4328867 to
d8cd472
Compare
|
Rebased again onto the latest |
d8cd472 to
c801c83
Compare
|
Diff looks right to me. The emitted bitmap is I pulled both versions of The new test also can't pass on Still behind |
c801c83 to
5c93e0e
Compare
|
Thanks for the independent validation. I rebased the unchanged patch onto the current |
|
Re-checked the rebase. The patch at Worth knowing before those runs get approved: |
Fixes #2531
What changed
window.devicePixelRatiointo screenshot downscalingdefaultViewport: nullpath with a forced 2x device scale factorWhy
Screenshot source boxes and CDP clip dimensions are expressed in CSS pixels, but the returned bitmap is scaled by the page's device pixel ratio. The previous calculation compared the CSS width directly with
screenshotMaxWidth, so a 2x page could return an image twice the configured bound.The new calculation derives the clip scale from
box × devicePixelRatio, making the limit apply to the image pixels sent to the model.Validation
npm run check-formatnpm run buildnpm run test -- tests/tools/screenshot.test.ts --test-name-pattern='honors screenshotMaxWidth at device scale factors above 1'npm run test -- tests/tools/screenshot.test.ts --test-skip-pattern='with full page resulting in a large screenshot'The new regression fails on
mainwith a 200px-wide image and passes with an exact 100px result after this change. I also attempted the full suite with retries; this local environment still times out in unrelated daemon/extension E2E tests and hits the existingPage.captureScreenshot: Page is too largecase, which reproduces on pristinemain.