From 401d84e4a3508f9ca5c24dbfcad2a71571b1b8eb Mon Sep 17 00:00:00 2001 From: Maksim Sadym <69349599+sadym-chromium@users.noreply.github.com> Date: Wed, 3 Feb 2021 14:30:46 +0100 Subject: [PATCH] feat: use `captureBeyondViewport` in `Page.captureScreenshot` (#6805) BREAKING CHANGE: - `page.screenshot` makes a screenshot with the clip dimensions, not cutting it by the ViewPort size. --- src/common/Page.ts | 15 ++--------- .../screenshot-offscreen-clip-artefacts.png | Bin 194 -> 0 bytes .../screenshot-offscreen-clip.png | Bin 161 -> 266 bytes .../screenshot-offscreen-clip-artefacts.png | Bin 279 -> 0 bytes test/screenshot.spec.ts | 24 ++---------------- 5 files changed, 4 insertions(+), 35 deletions(-) delete mode 100644 test/golden-chromium/screenshot-offscreen-clip-artefacts.png delete mode 100644 test/golden-firefox/screenshot-offscreen-clip-artefacts.png diff --git a/src/common/Page.ts b/src/common/Page.ts index 9df29693c1a..cf313bcfbbc 100644 --- a/src/common/Page.ts +++ b/src/common/Page.ts @@ -1680,20 +1680,8 @@ export class Page extends EventEmitter { const width = Math.ceil(metrics.contentSize.width); const height = Math.ceil(metrics.contentSize.height); - // Overwrite clip for full page at all times. + // Overwrite clip for full page. clip = { x: 0, y: 0, width, height, scale: 1 }; - const { isMobile = false, deviceScaleFactor = 1, isLandscape = false } = - this._viewport || {}; - const screenOrientation: Protocol.Emulation.ScreenOrientation = isLandscape - ? { angle: 90, type: 'landscapePrimary' } - : { angle: 0, type: 'portraitPrimary' }; - await this._client.send('Emulation.setDeviceMetricsOverride', { - mobile: isMobile, - width, - height, - deviceScaleFactor, - screenOrientation, - }); } const shouldSetDefaultBackground = options.omitBackground && format === 'png'; @@ -1705,6 +1693,7 @@ export class Page extends EventEmitter { format, quality: options.quality, clip, + captureBeyondViewport: true, }); if (shouldSetDefaultBackground) await this._client.send('Emulation.setDefaultBackgroundColorOverride'); diff --git a/test/golden-chromium/screenshot-offscreen-clip-artefacts.png b/test/golden-chromium/screenshot-offscreen-clip-artefacts.png deleted file mode 100644 index c41be2be1e7fa3c00975328be5f0f9864a773d60..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 194 zcmeAS@N?(olHy`uVBq!ia0vp^DImna**Z)9p{>=X~XEtrxw0iaG zl`B_Hn>NkU(^F4RPf1BhOiT=@@Y3b-79bVr>EaktaqI2rjl2y8JPeNO4{(VoWVtzh zGRZl}X28Vy`J$k?rp_d#Q}Oji_kJ1rZ+fOZ)pxSzrfJGC-%MlVc*U0nXuK6Kel_*r n!T^n2*ebhCsCo z3j`dIoGCoDy`<9t3^q9{ad2>WGCFH0Xa1i#vv1$N zJ$v?S*|KHr+O;cJuADx7dVha^a&oedkB_^%yOEKRo}QkTmX@ljs*H>bA0Ho3?+LZ^ z{XmMbB*-tA!Qt5rkhyK1E{-7;x8C0H { - const { page, server } = getTestState(); - await page.setViewport({ width: 50, height: 50 }); - await page.goto(server.PREFIX + '/grid.html'); - const screenshot = await page.screenshot({ - clip: { - x: 25, - y: 25, - width: 100, - height: 100, - }, - }); - expect(screenshot).toBeGolden('screenshot-offscreen-clip.png'); - }); - // TODO: remove after the screenshot is fixed. - // https://crbug.com/1173457 itFailsFirefox( - 'should clip elements to the viewport size with artefacts', + 'should get screenshot bigger than the viewport', async () => { const { page, server } = getTestState(); await page.setViewport({ width: 50, height: 50 }); @@ -82,9 +64,7 @@ describe('Screenshots', function () { height: 100, }, }); - expect(screenshot).toBeGolden( - 'screenshot-offscreen-clip-artefacts.png' - ); + expect(screenshot).toBeGolden('screenshot-offscreen-clip.png'); } ); it('should run in parallel', async () => {