Skip to content

fix(screenshot): error when webp dimensions exceed 16383px limit - #42721

Closed
Mohan Ram (mohanram-dev) wants to merge 1 commit into
microsoft:mainfrom
mohanram-dev:fix/webp-screenshot-dimension-limit
Closed

Mohan Ram (mohanram-dev) wants to merge 1 commit into
microsoft:mainfrom
mohanram-dev:fix/webp-screenshot-dimension-limit

Conversation

@mohanram-dev

Copy link
Copy Markdown

Fixes #42717

Description

WebP format uses 14 bits for pixel width and height (2^14 - 1 = 16,383 px maximum). When taking a screenshot with type: 'webp' where either width or height exceeds 16,383 pixels:

  1. Chromium's Skia encoder cannot encode the image into WebP and returns empty image data ({ data: '' }).
  2. Playwright previously converted this to a 0-byte Buffer (Buffer.from('', 'base64')) and silently returned it as a successful screenshot.
  3. In @playwright/mcp, browser_take_screenshot wrote a 0-byte file to disk and returned an empty image without raising an error.

Changes

  • In crPage.ts, compute renderScale (factoring in deviceScaleFactor when scale: 'device'). If format === 'webp' and either width or height exceeds 16,383 pixels, throw Cannot take screenshot larger than 16383 pixels on any dimension when using webp format.
  • In crPage.ts and screenshotter.ts, guard against empty screenshot data by throwing Failed to take screenshot, received empty image data from browser if empty data is returned.
  • In wkPage.ts and wvPage.ts, validate the 16,383 px limit for WebP format in validateScreenshotDimension.
  • In @playwright/mcp's browser_take_screenshot tool, ensure empty image data throws an error rather than writing a 0-byte file.
  • Added regression tests in tests/mcp/screenshot.spec.ts and tests/page/page-screenshot.spec.ts.

@dcrousso

Copy link
Copy Markdown
Contributor

this is really an upstream issue and should be fixed there instead (and also i dont think it's really all that likely/common for a screenshot to be that large in the first place)

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.

[MCP] WebP screenshot above 16383 px returns an empty image

2 participants