Skip to content

Commit

Permalink
feat: accept captureBeyondViewport as optional screenshot param (#7063)
Browse files Browse the repository at this point in the history
Issue: #7063
  • Loading branch information
galr52 authored and mathiasbynens committed Apr 7, 2021
1 parent 66a0d5c commit 0e092d2
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/common/Page.ts
Expand Up @@ -183,6 +183,11 @@ export interface ScreenshotOptions {
* @defaultValue 'binary'
*/
encoding?: 'base64' | 'binary';
/**
* If you need a screenshot bigger than the Viewport
* @defaultValue true
*/
captureBeyondViewport?: boolean;
}

/**
Expand Down Expand Up @@ -1796,6 +1801,9 @@ export class Page extends EventEmitter {
targetId: this._target._targetId,
});
let clip = options.clip ? processClip(options.clip) : undefined;
let { captureBeyondViewport = true } = options;
captureBeyondViewport =
typeof captureBeyondViewport === 'boolean' ? captureBeyondViewport : true;

if (options.fullPage) {
const metrics = await this._client.send('Page.getLayoutMetrics');
Expand All @@ -1804,17 +1812,33 @@ export class Page extends EventEmitter {

// Overwrite clip for full page.
clip = { x: 0, y: 0, width, height, scale: 1 };

if (!captureBeyondViewport) {
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';
if (shouldSetDefaultBackground) {
await this._setTransparentBackgroundColor();
}

const result = await this._client.send('Page.captureScreenshot', {
format,
quality: options.quality,
clip,
captureBeyondViewport: true,
captureBeyondViewport,
});
if (shouldSetDefaultBackground) {
await this._resetDefaultBackgroundColor();
Expand Down

0 comments on commit 0e092d2

Please sign in to comment.