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'
|
* @defaultValue 'binary'
|
||||||
*/
|
*/
|
||||||
encoding?: 'base64' | '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,
|
targetId: this._target._targetId,
|
||||||
});
|
});
|
||||||
let clip = options.clip ? processClip(options.clip) : undefined;
|
let clip = options.clip ? processClip(options.clip) : undefined;
|
||||||
|
let { captureBeyondViewport = true } = options;
|
||||||
|
captureBeyondViewport =
|
||||||
|
typeof captureBeyondViewport === 'boolean' ? captureBeyondViewport : true;
|
||||||
|
|
||||||
if (options.fullPage) {
|
if (options.fullPage) {
|
||||||
const metrics = await this._client.send('Page.getLayoutMetrics');
|
const metrics = await this._client.send('Page.getLayoutMetrics');
|
||||||
@ -1804,17 +1812,33 @@ export class Page extends EventEmitter {
|
|||||||
|
|
||||||
// Overwrite clip for full page.
|
// Overwrite clip for full page.
|
||||||
clip = { x: 0, y: 0, width, height, scale: 1 };
|
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 =
|
const shouldSetDefaultBackground =
|
||||||
options.omitBackground && format === 'png';
|
options.omitBackground && format === 'png';
|
||||||
if (shouldSetDefaultBackground) {
|
if (shouldSetDefaultBackground) {
|
||||||
await this._setTransparentBackgroundColor();
|
await this._setTransparentBackgroundColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await this._client.send('Page.captureScreenshot', {
|
const result = await this._client.send('Page.captureScreenshot', {
|
||||||
format,
|
format,
|
||||||
quality: options.quality,
|
quality: options.quality,
|
||||||
clip,
|
clip,
|
||||||
captureBeyondViewport: true,
|
captureBeyondViewport,
|
||||||
});
|
});
|
||||||
if (shouldSetDefaultBackground) {
|
if (shouldSetDefaultBackground) {
|
||||||
await this._resetDefaultBackgroundColor();
|
await this._resetDefaultBackgroundColor();
|
||||||
|
Loading…
Reference in New Issue
Block a user