microsoft/playwright · error · Error

Cannot take screenshot larger than 32767 pixels on any dimen

Error message

Cannot take screenshot larger than 32767 pixels on any dimension

What it means

validateScreenshotDimension() enforces a 32767-pixel hard limit per dimension on non-macOS WebKit, because the Cairo-based image backend (Linux/Windows) cannot produce larger images (microsoft/playwright#16727). The check multiplies the requested side by deviceScaleFactor unless scale:'css' / omitDeviceScaleFactor.

Source

Thrown at packages/playwright-core/src/server/webkit/wkPage.ts:871

  private _toolbarHeight(): number {
    if (this._page.browserContext._browser?.options.headful) {
      // note: historically, value for mac10.15 was 55
      if (hostPlatform === 'mac26-arm64' || hostPlatform === 'mac26')
        return 69;
      return 59;
    }
    return 0;
  }

  private validateScreenshotDimension(side: number, omitDeviceScaleFactor: boolean) {
    // Cairo based implementations (Linux and Windows) have hard limit of 32767
    // (see https://github.com/microsoft/playwright/issues/16727).
    if (process.platform === 'darwin')
      return;
    if (!omitDeviceScaleFactor && this._page.browserContext._options.deviceScaleFactor)
      side = Math.ceil(side * this._page.browserContext._options.deviceScaleFactor);
    if (side > 32767)
      throw new Error('Cannot take screenshot larger than 32767 pixels on any dimension');
  }

  async takeScreenshot(progress: Progress, format: string, documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, scale: 'css' | 'device'): Promise<Buffer> {
    const rect = (documentRect || viewportRect)!;
    const omitDeviceScaleFactor = scale === 'css';
    this.validateScreenshotDimension(rect.width, omitDeviceScaleFactor);
    this.validateScreenshotDimension(rect.height, omitDeviceScaleFactor);
    // WebKit on macOS has no built-in WebP encoder, so capture a PNG and re-encode it.
    const recodePngToWebp = format === 'webp' && process.platform === 'darwin';
    const result = await progress.race(this._session.send('Page.snapshotRect', { ...rect, coordinateSystem: documentRect ? 'Page' : 'Viewport', omitDeviceScaleFactor, format: (recodePngToWebp ? 'png' : format) as 'png' | 'jpeg' | 'webp', quality: recodePngToWebp ? undefined : quality }));
    // Strip the 'data:image/<format>;base64,' prefix.
    const buffer = Buffer.from(result.dataURL.substring(result.dataURL.indexOf(',') + 1), 'base64');
    if (recodePngToWebp) {
      const png = PNG.sync.read(buffer);
      const image = { width: png.width, height: png.height, data: png.data };
      // Match the native WebKit encoder: webp quality 100 (or omitted) is lossless.
      return (quality === undefined || quality >= 100) ? encodeWebp(image, { lossless: true }) : encodeWebp(image, { quality });
    }

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Reduce deviceScaleFactor for large screenshots, or pass scale:'css' to omit the device-scale multiplier.
  2. Cap the screenshot region: clip the page into sub-32767 pieces and stitch, or screenshot only a scrolled viewport window.
  3. Run the screenshot step on macOS where the limit does not apply.

Example fix

// before
await page.screenshot({ fullPage: true, path: 'p.png' }); // tall page, Linux

// after
await page.screenshot({ fullPage: true, scale: 'css', path: 'p.png' });
Defensive patterns

Strategy: validation

Validate before calling

const MAX = 32767;
function fitsWk(side, dsf, omitDsf) {
  if (process.platform === 'darwin') return true;
  return (omitDsf ? side : Math.ceil(side * (dsf || 1))) <= MAX;
}

Type guard

null

Try / catch

try { return await page.screenshot({ fullPage: true }); }
catch (e) {
  if (/32767/.test(e.message)) return await page.screenshot({ fullPage: true, scale: 'css' });
  throw e;
}

Prevention

When it happens

Trigger: Calling page.screenshot() with a clip/full-page region whose width or height (times deviceScaleFactor) exceeds 32767 on Linux/Windows WebKit. Common with fullPage screenshots of very long pages or high deviceScaleFactor.

Common situations: fullPage:true on infinitely-scrolling or very tall pages. deviceScaleFactor:2-3 amplifying an already-large clip. CI on Linux runners (macOS is exempt from this check).

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/62dff69db00a7767. Report an issue: GitHub.