fix: downscale viewport screenshots when no viewport is emulated#2380
Open
thomasbachem wants to merge 1 commit into
Open
fix: downscale viewport screenshots when no viewport is emulated#2380thomasbachem wants to merge 1 commit into
thomasbachem wants to merge 1 commit into
Conversation
`--screenshot-max-width`/`--screenshot-max-height` never applied to a plain viewport screenshot. `getSourceBox()` reads `page.viewport()` and bails when it is null, so no clip was computed and the capture came back at full size. `page.viewport()` is null in normal usage: the connect and launch paths both pass `defaultViewport: null`, and nothing sets a viewport unless `emulate` is called with one – `--viewport` sets the window bounds, and `resize_page` moves the window. Full page and element screenshots were unaffected because they take the other `getSourceBox()` branches. Fall back to the window's own `innerWidth`/`innerHeight`, which is the area a viewport screenshot already captures, so the clip only applies `scale` and the framing is unchanged. The existing coverage missed this because it calls `page.setViewport()` first, which is the one condition under which the flags worked.
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.
Fixes #2379.
getSourceBox()bails whenpage.viewport()is null, which is the normal case – the browser is launched and connected withdefaultViewport: null, and onlyemulatesets a viewport. So--screenshot-max-width/--screenshot-max-heightnever produced a clip for a plain viewport screenshot.This falls back to the window's own
innerWidth/innerHeight. That's the area a viewport screenshot already captures, so the clip only appliesscaleand the framing is unchanged. Full page and element shots keep their existing branches.Testing
Added
downscales viewport screenshot when no viewport is emulated, which omits thesetViewport()call the existing downscale tests make – it fails onmain(expected: 100, actual: 1200, the window width) and passes here. Fulltests/tools/screenshot.test.tsis green.