Repository navigation
Description
Description of the bug
When --screenshot-max-width or --screenshot-max-height causes a screenshot to be downscaled, take_screenshot captures the top-left of the document instead of the current viewport after scrolling. Element screenshots using uid are also offset by the page's scroll position.
The screenshot can therefore show an unrelated area when debugging a scrolled page.
Reproduction
Start the server with the configuration below, then:
-
Call
new_pagewithurl: "about:blank". Use the returned page ID for the following page-scoped calls. -
Call
emulatewithviewport: "800x600x1". -
Call
evaluate_scriptwith this function:() => { document.body.style.margin = '0'; document.body.innerHTML = ` <div style="height:1000px;background:red"></div> <div style="height:1000px;background:blue"></div> `; window.scrollTo(0, 1000); return {scrollY: window.scrollY}; }
-
Call
take_screenshotwith the page ID and otherwise default parameters.
Actual: the returned 200×150 image is red, although the current viewport is blue. Removing the screenshot size limit returns the correct blue viewport.
Separate checks on left-to-right pages reproduced the issue with horizontal scrolling, without viewport emulation, and with element screenshots using uid. Full-page screenshots captured the correct region in those checks.
Expectation
The screenshot should show the same region with or without the size limit. In this example, it should be a blue 200×150 image.
The configuration reference describes the size limits as downscaling the captured image while preserving its aspect ratio. The tool reference distinguishes full-page capture from the currently visible viewport.
For viewport and element screenshots, the downscale path passes viewport-relative coordinates from getSourceBox() to page.screenshot({clip}), which needs document coordinates. The page scroll offset is missing.
Related: #2380 fixed downscaling without an emulated viewport, and #2536 fixed the size bound on HiDPI displays. This report concerns the captured region after scrolling.
MCP configuration
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"-y",
"chrome-devtools-mcp@1.8.0",
"--headless",
"--isolated",
"--screenshot-max-width",
"200",
"--no-usage-statistics"
]
}
}
}Chrome DevTools MCP version
1.8.0 (npm package); also reproduced on main at dc1d559.
Chrome version
Chrome for Testing 152.0.7977.75, selected with --executable-path in the reproduction harness.
Coding agent version
Standalone MCP client using @modelcontextprotocol/sdk 1.30.0.
Model version
No response
Chat log
No response
Node version
v24.12.0
Operating system
macOS
Extra checklist
- I want to provide a PR to fix this bug
Activity
bickov commentedon Sep 14, 2026
Worth a test case for fixed and sticky elements while you're in there. Once the clip is computed in document coordinates, anything position:fixed is still painted at the top of the viewport, so a scrolled capture can end up with the header sitting in the middle of the image or showing up twice. Bites scrolling capture in general, not just this path.
ddussi commentedon Sep 16, 2026
@bickov Thanks for pointing this out! I’ve added local regression tests for fixed and sticky headers after scrolling, covering emulated and native viewport captures as well as element screenshots, with and without downscaling. The pixel checks verify that the headers stay in the expected position without duplication, and that the scroll position is preserved. All 29 screenshot tests pass locally. I’ll include these tests in #2685.
bickov commentedon Sep 16, 2026
@ddussi One more case to cover. Headers pinned to the top or bottom edge are the easy version, and the tests sound like they handle those.
The harder ones appear partway down the page. A cookie banner with a scroll threshold. A floating toolbar that sits in the middle of the viewport and touches neither edge. Detection that samples only the top and bottom strips of a frame will not see them. The header does not duplicate in that case. The offset comes out wrong instead.
Second case is a sticky header that changes height as you scroll, say 80px down to 48px. The element is the same in frame 1 and frame 4, at two different sizes.
Prior art in case it is useful: puppeteer #1576 has been open on this since December 2017, still labelled confirmed and upstream, and playwright #30331 since April 2024. I pulled those together with the captureBeyondViewport behaviour on my blog: https://slimsnap.ai/blog/fixed-header-full-page-screenshot