feat: accept captureBeyondViewport as optional screenshot param (#7063)
Issue: #7063
This commit is contained in:
parent
66a0d5cbcc
commit
0e092d2ea0
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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');
|
||||
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user