diff --git a/x-pack/platform/plugins/shared/screenshotting/server/layouts/create_layout.test.ts b/x-pack/platform/plugins/shared/screenshotting/server/layouts/create_layout.test.ts index 4c660ef8cad46..c9046d0d3a3d6 100644 --- a/x-pack/platform/plugins/shared/screenshotting/server/layouts/create_layout.test.ts +++ b/x-pack/platform/plugins/shared/screenshotting/server/layouts/create_layout.test.ts @@ -33,6 +33,7 @@ describe('Create Layout', () => { }, "useReportingBranding": true, "width": 16, + "zoom": 2, } `); }); diff --git a/x-pack/platform/plugins/shared/screenshotting/server/layouts/preserve_layout.test.ts b/x-pack/platform/plugins/shared/screenshotting/server/layouts/preserve_layout.test.ts index 03dbadd006a0f..e12c9587aaec1 100644 --- a/x-pack/platform/plugins/shared/screenshotting/server/layouts/preserve_layout.test.ts +++ b/x-pack/platform/plugins/shared/screenshotting/server/layouts/preserve_layout.test.ts @@ -56,3 +56,18 @@ it('preserve layout allows customizable selectors', () => { } `); }); + +it('preserve layout use a default zoom of 2', () => { + const testPreserveLayout = new PreserveLayout({ width: 1000, height: 2000 }); + expect(testPreserveLayout.getBrowserZoom()).toBe(2); + expect(testPreserveLayout.getBrowserViewport().height).toBe(4000); +}); + +it('preserve layout caps browser zoom for extremely large screenshots to avoid Chromium artifacts', () => { + // A very tall layout would exceed Chrome limits at zoom=2. + const testPreserveLayout = new PreserveLayout({ width: 1727, height: 15000 }); + + // The zoom should be reduced so that output height stays <= 16000 pixels. + expect(testPreserveLayout.getBrowserZoom()).toBe(1); + expect(testPreserveLayout.getBrowserViewport().height).toBeLessThanOrEqual(16000); +}); diff --git a/x-pack/platform/plugins/shared/screenshotting/server/layouts/preserve_layout.ts b/x-pack/platform/plugins/shared/screenshotting/server/layouts/preserve_layout.ts index b56177484f7e5..7ae11f5d15b22 100644 --- a/x-pack/platform/plugins/shared/screenshotting/server/layouts/preserve_layout.ts +++ b/x-pack/platform/plugins/shared/screenshotting/server/layouts/preserve_layout.ts @@ -12,13 +12,18 @@ import type { Layout } from '.'; import { BaseLayout } from './base_layout'; import type { PageSizeParams } from './base_layout'; -// We use a zoom of two to bump up the resolution of the screenshot a bit. -const ZOOM: number = 2; +// We default to a zoom of two to bump up the resolution of the screenshot a bit. +// However, Chromium/Skia has a height limit of 16384px, so for anything larger +// than 8000, we should use a zoom of one. +// https://github.com/puppeteer/puppeteer/issues/359 +const DEFAULT_ZOOM = 2; +const MAX_HEIGHT_PX = 8000; export class PreserveLayout extends BaseLayout implements Layout { public readonly selectors: LayoutSelectorDictionary; public readonly height: number; public readonly width: number; + private readonly zoom: number; private readonly scaledHeight: number; private readonly scaledWidth: number; @@ -26,8 +31,9 @@ export class PreserveLayout extends BaseLayout implements Layout { super('preserve_layout'); this.height = size.height; this.width = size.width; - this.scaledHeight = size.height * ZOOM; - this.scaledWidth = size.width * ZOOM; + this.zoom = this.height <= MAX_HEIGHT_PX ? DEFAULT_ZOOM : 1; + this.scaledHeight = size.height * this.zoom; + this.scaledWidth = size.width * this.zoom; this.selectors = { ...DEFAULT_SELECTORS, ...selectors }; } @@ -45,14 +51,14 @@ export class PreserveLayout extends BaseLayout implements Layout { } public getBrowserZoom() { - return ZOOM; + return this.zoom; } public getViewport() { return { height: this.height, width: this.width, - zoom: ZOOM, + zoom: this.zoom, }; }