{"record":{"id":"62dff69db00a7767","repo":"microsoft/playwright","slug":"cannot-take-screenshot-larger-than-32767-pixels-on-62dff6","errorCode":null,"errorMessage":"Cannot take screenshot larger than 32767 pixels on any dimension","messagePattern":"Cannot take screenshot larger than 32767 pixels on any dimension","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/webkit/wkPage.ts","lineNumber":871,"sourceCode":"  private _toolbarHeight(): number {\n    if (this._page.browserContext._browser?.options.headful) {\n      // note: historically, value for mac10.15 was 55\n      if (hostPlatform === 'mac26-arm64' || hostPlatform === 'mac26')\n        return 69;\n      return 59;\n    }\n    return 0;\n  }\n\n  private validateScreenshotDimension(side: number, omitDeviceScaleFactor: boolean) {\n    // Cairo based implementations (Linux and Windows) have hard limit of 32767\n    // (see https://github.com/microsoft/playwright/issues/16727).\n    if (process.platform === 'darwin')\n      return;\n    if (!omitDeviceScaleFactor && this._page.browserContext._options.deviceScaleFactor)\n      side = Math.ceil(side * this._page.browserContext._options.deviceScaleFactor);\n    if (side > 32767)\n      throw new Error('Cannot take screenshot larger than 32767 pixels on any dimension');\n  }\n\n  async takeScreenshot(progress: Progress, format: string, documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, scale: 'css' | 'device'): Promise<Buffer> {\n    const rect = (documentRect || viewportRect)!;\n    const omitDeviceScaleFactor = scale === 'css';\n    this.validateScreenshotDimension(rect.width, omitDeviceScaleFactor);\n    this.validateScreenshotDimension(rect.height, omitDeviceScaleFactor);\n    // WebKit on macOS has no built-in WebP encoder, so capture a PNG and re-encode it.\n    const recodePngToWebp = format === 'webp' && process.platform === 'darwin';\n    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 }));\n    // Strip the 'data:image/<format>;base64,' prefix.\n    const buffer = Buffer.from(result.dataURL.substring(result.dataURL.indexOf(',') + 1), 'base64');\n    if (recodePngToWebp) {\n      const png = PNG.sync.read(buffer);\n      const image = { width: png.width, height: png.height, data: png.data };\n      // Match the native WebKit encoder: webp quality 100 (or omitted) is lossless.\n      return (quality === undefined || quality >= 100) ? encodeWebp(image, { lossless: true }) : encodeWebp(image, { quality });\n    }","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/webkit/wkPage.ts#L853-L889","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Reduce deviceScaleFactor for large screenshots, or pass scale:'css' to omit the device-scale multiplier.","Cap the screenshot region: clip the page into sub-32767 pieces and stitch, or screenshot only a scrolled viewport window.","Run the screenshot step on macOS where the limit does not apply."],"exampleFix":"// before\nawait page.screenshot({ fullPage: true, path: 'p.png' }); // tall page, Linux\n\n// after\nawait page.screenshot({ fullPage: true, scale: 'css', path: 'p.png' });","handlingStrategy":"validation","validationCode":"const MAX = 32767;\nfunction fitsWk(side, dsf, omitDsf) {\n  if (process.platform === 'darwin') return true;\n  return (omitDsf ? side : Math.ceil(side * (dsf || 1))) <= MAX;\n}","typeGuard":"null","tryCatchPattern":"try { return await page.screenshot({ fullPage: true }); }\ncatch (e) {\n  if (/32767/.test(e.message)) return await page.screenshot({ fullPage: true, scale: 'css' });\n  throw e;\n}","preventionTips":["Use scale:'css' for large screenshots to skip device-scale multiplication.","On Linux/Windows, lower deviceScaleFactor or clip tall pages."],"tags":["webkit","screenshot","cairo","linux","windows","device-scale-factor"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}