Skip to content

Claude errors if the image dimensions exceed 8000 pixels #879

Closed

Description

@sebastienkothe

Problem

When using take_screenshot on large viewports (e.g., testing responsive design on wide monitors or using fullPage: true on long pages), the tool fails with:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.7.content.2.image.source.base64.data: At least one of the image dimensions exceed max allowed size: 8000 pixels"}}

This happens frequently when testing responsive layouts, making the tool unusable for this common use case.

Expected behavior

Screenshots should be automatically resized to fit within Claude API limits (max 8000px per dimension) before being sent, preserving aspect ratio.

Reproduction

  1. Open a page in a browser with a large viewport or long scrollable content
  2. Call take_screenshot (especially with fullPage: true)
  3. Tool fails with the above error

Suggested fix

Resize images before base64 encoding when any dimension exceeds 8000px, preserving aspect ratio. This is a common pattern in similar tools.

Environment

  • MCP: chrome-devtools-mcp (latest via npx)
  • Client: Claude Code
  • OS: macOS

Activity

  1. OrKoN commented on Feb 3, 2026

    @OrKoN
    Collaborator

    The MCP spec does not place limits on the image as far as I know. Do you know why 8000px is chosen? The existing workaround would be to save large images to file by passing the filePath parameter or calling page_resize beforehand.

  2. added theissue type on Feb 3, 2026
  3. OrKoN commented on Feb 3, 2026

    @OrKoN
    Collaborator

    Related Claude issue anthropics/claude-code#2939

  4. changed the title [-]take_screenshot fails when image dimension exceeds 8000 pixels[/-] [+]Claude errors if the image dimensions exceed 8000 pixels[/+] on Feb 3, 2026
  5. removed theissue type on Feb 3, 2026
  6. added theissue type on Feb 3, 2026
  7. sebastienkothe commented on Feb 3, 2026

    @sebastienkothe
    Author

    The 8000px limit comes from Claude API's image constraints.

    From the official Anthropic documentation:

    If you submit an image larger than 8000x8000 px, it will be rejected. If you submit more than 20 images in one API request, this limit is 2000x2000 px.

    Context Max size per image
    1-20 images 8000×8000 px
    21-100 images 2000×2000 px

    This explains both error messages seen in related issues (8000px vs 2000px depending on context).

    Thanks for the workaround suggestions (filePath and page_resize). An automatic resize before sending to the API would still be a nice quality-of-life improvement to avoid these errors entirely.

  8. simplylizz commented on Feb 7, 2026

    @simplylizz

    I’ve been experiencing the same issue for quite some time, and it’s pretty annoying because it corrupts the Claude Code session.

    Ideally, this should be fixed in Claude Code itself, but this bug has existed for a long time and is still present. So maybe it’s worth introducing some configurable parameters on the MCP side: one option could be automatic resizing if any side exceeds X pixels; another could be to fail the call with a clear error message stating that the screenshot exceeds specified size limit. This way, we would be able to set different settings and limits for different API providers or agentic coding tools.

  9. sitefinitysteve commented on Feb 8, 2026

    @sitefinitysteve

    ● chrome-devtools - take_screenshot (MCP)
    ⎿ # take_screenshot response
    Took a screenshot of the current page's viewport.
    ⎿ [Image]
    ⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.57.content.1.image.source.base64.data: At least one of the image dimensions exceed max allowed size for many-image requests: 2000
    pixels"},"request_id":"req_011CXvuVWi58eazvVLm8123w"}

    Would be just nice to handle on the MCP screenshot tool, even if it's a resize or something. Sucks to just have an entire chat session get messed up

  10. OrKoN commented on Feb 9, 2026

    @OrKoN
    Collaborator

    Please also post this on anthropics/claude-code#2939 We will see if we can have a work around here but if Claude Code fixes this, it would be ideal.

  11. sebastienkothe commented on Feb 9, 2026

    @sebastienkothe
    Author

    Thanks @OrKoN for the pointer! I'll cross-post on anthropics/claude-code#2939 with context about the MCP screenshot side of the problem.

    Really appreciate you linking the issues together and being open to a workaround on the MCP side as well.

  12. MussaCharles commented on Feb 9, 2026

    @MussaCharles

    In case anyone missed it. I built a workaround that auto-resizes oversized images before they reach the API. It's completely resolved this issue with chrome-devtools-mcp and most screenshot based tools like Playwright for me. Works as a Claude Code hook or plugin:

  13. natorion commented on Feb 13, 2026

    @natorion
    Contributor

    This has to be fixed on the Claude side AFAIK. Limits are dependend on the MCP client and how it handles the images. Limits will also change when models change. It's not feasible for us to maintain this.

    filePath is exactly the solution that should be used in such cases. I wonder, does Claude not try it again with that particular parameter enabled, after it fails?

  14. OrKoN commented on Feb 18, 2026

    @OrKoN
    Collaborator

    filePath is exactly the solution that should be used in such cases. I wonder, does Claude not try it again with that particular parameter enabled, after it fails?

    because it polluted its request history with an image that is too large and does not recover from that. I think even file path might not work if it tried to load the image from file into its context window. It seems to be also conditional and starts to fail for images of 2000px if there are more than 20 images in claude code history.

  15. antoinekm commented on Apr 7, 2026

    @antoinekm
    Contributor

    @OrKoN @natorion I took a stab at this with the design constraints from this thread in mind. PR is up at #1823.

    The PR adds opt-in CLI flags so operators can cap screenshot size before the image is returned. With no flags set, behavior is byte-identical to today, which keeps the maintenance burden at zero for users who don't opt in:

    • --screenshot-format <jpeg|png|webp>: override the default format
    • --screenshot-quality <0-100>: override the default JPEG/WebP quality
    • --screenshot-max-width <px>: downscale screenshots wider than this
    • --screenshot-max-height <px>: downscale taller screenshots (combines with --screenshot-max-width; the smaller scale wins so both bounds are respected while preserving aspect ratio)

    For the exact error in this issue, the recipe is:

    chrome-devtools-mcp --screenshot-max-width=8000 --screenshot-max-height=8000
    # or, if many images may end up in the same request:
    chrome-devtools-mcp --screenshot-max-width=2000 --screenshot-max-height=2000

    Addressing the concerns raised here

    "It's not feasible for us to maintain this. Limits will change when models change."

    The MCP server hardcodes no LLM-specific limits. The flags are pure parameters; operators pick values that match their client/model. When a vendor raises a limit next year, no code change is needed here, only the operator's CLI args change.

    "filePath / page_resize already exist as workarounds."

    True, but as @OrKoN noted earlier in the thread, filePath doesn't fully recover because the failure keeps happening as soon as the call result tries to load the image into context. And page_resize works but mutates the page being debugged, which can break the very session the user is trying to capture. The resize in this PR happens between Puppeteer and the MCP response, so the inspected page is untouched.

    "Should be fixed client side."

    Agreed, and I think both fixes are complementary, not competing. A client-side fix (compaction evicts/downsamples old images) handles the cumulative case for any MCP. A server-side cap handles the per-call dimension limit for users who hit it before compaction can kick in. The two address overlapping but distinct failure modes.

    Implementation

    • Resize uses Puppeteer's built-in clip.scale (CDP Page.captureScreenshot), so no new dependencies.
    • Works for viewport, full-page (fullPage: true) and element (uid) captures alike.
    • ~150 lines of source code, ~200 lines of new tests; all 627 tests in the suite pass.
    • Aligned with the "Reference over Value" principle in docs/design-principles.md: the existing 2 MB temp-file fallback is preserved; only the inline base64 path is reduced.

    Trying it before the PR lands

    git clone https://github.com/ChromeDevTools/chrome-devtools-mcp
    cd chrome-devtools-mcp
    git fetch origin pull/1823/head:pr-1823
    git checkout pr-1823
    npm ci && npm run build

    Then point your MCP client at the local build:

    {
      "mcpServers": {
        "chrome-devtools": {
          "command": "node",
          "args": [
            "/absolute/path/to/chrome-devtools-mcp/build/src/bin/chrome-devtools-mcp.js",
            "--screenshot-format=jpeg",
            "--screenshot-max-width=2000",
            "--screenshot-max-height=2000"
          ]
        }
      }
    }

    Happy to iterate on the design in #1823 if any of the trade-offs above are unacceptable. If you prefer a different approach (e.g. lowering the existing 2 MB inline threshold, or rejecting the PR entirely in favor of waiting for a client-side fix), I'm fine with that too. Just wanted to put a concrete option on the table.

  16. bickov commented on Jul 13, 2026

    @bickov

    fullPage: true is the pathological case for this and it's worth naming why.

    I measured a retina full-page capture: 3066 x 28800 goes in, 276 x 2600 is what the model receives. Aspect ratio is preserved, so on a long page the height is the long edge, and pulling it under the cap drags the width down with it. About 99% of the pixels gone, 14pt text under 3px tall.

    So resizing before the send clears the 400, but the model then reads a gray smear. For fullPage specifically, tiling the capture into several frames (each under the limit, in order) keeps the text readable in a way a single resized image can't.

    @MussaCharles 's sanitizer solves the hard-error half nicely. A tile mode would solve the readability half.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions