Skip to content

fix: downscale viewport screenshots when no viewport is emulated#2380

Open
thomasbachem wants to merge 1 commit into
ChromeDevTools:mainfrom
thomasbachem:fix/downscale-without-explicit-viewport
Open

fix: downscale viewport screenshots when no viewport is emulated#2380
thomasbachem wants to merge 1 commit into
ChromeDevTools:mainfrom
thomasbachem:fix/downscale-without-explicit-viewport

Conversation

@thomasbachem

Copy link
Copy Markdown
Contributor

Fixes #2379.

getSourceBox() bails when page.viewport() is null, which is the normal case – the browser is launched and connected with defaultViewport: null, and only emulate sets a viewport. So --screenshot-max-width/--screenshot-max-height never 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 applies scale and 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 the setViewport() call the existing downscale tests make – it fails on main (expected: 100, actual: 1200, the window width) and passes here. Full tests/tools/screenshot.test.ts is green.

`--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.
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.

--screenshot-max-width/height are ignored for viewport screenshots

1 participant