Skip to content

Downscaled screenshots capture the wrong region after scrolling #2684

Closed

Description

@ddussi

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:

  1. Call new_page with url: "about:blank". Use the returned page ID for the following page-scoped calls.

  2. Call emulate with viewport: "800x600x1".

  3. Call evaluate_script with 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};
    }
  4. Call take_screenshot with 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

  1. added theissue type on Sep 7, 2026
  2. bickov commented on Sep 14, 2026

    @bickov

    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.

  3. ddussi commented on Sep 16, 2026

    @ddussi
    ContributorAuthor

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

  4. bickov commented on Sep 16, 2026

    @bickov

    @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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions