Skip to content

Commit

Permalink
Add fromSurface option
Browse files Browse the repository at this point in the history
  • Loading branch information
LeviPesin committed Jun 9, 2022
1 parent 465a7c4 commit bdfba51
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/common/Page.ts
Expand Up @@ -192,10 +192,15 @@ export interface ScreenshotOptions {
*/
encoding?: 'base64' | 'binary';
/**
* If you need a screenshot bigger than the Viewport
* Capture the screenshot beyond the viewport.
* @defaultValue true
*/
captureBeyondViewport?: boolean;
/**
* Capture the screenshot from the surface, rather than the view.
* @defaultValue true
*/
fromSurface?: boolean;
}

/**
Expand Down Expand Up @@ -2642,7 +2647,7 @@ export class Page extends EventEmitter {
* applicable to `png` images.
*
* - `fullPage` : When true, takes a screenshot of the full
* scrollable page. Defaults to `false`
* scrollable page. Defaults to `false`.
*
* - `clip` : An object which specifies clipping region of the page.
* Should have the following fields:<br/>
Expand All @@ -2652,11 +2657,21 @@ export class Page extends EventEmitter {
* - `height` : height of clipping area.
*
* - `omitBackground` : Hides default white background and allows
* capturing screenshots with transparency. Defaults to `false`
* capturing screenshots with transparency. Defaults to `false`.
*
* - `encoding` : The encoding of the image, can be either base64 or
* binary. Defaults to `binary`.
*
* - `captureBeyondViewport` : When true, captures screenshot
* {@link https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-captureScreenshot
* | beyond the viewport}. When false, falls back to old behaviour,
* and cuts the screenshot by the viewport size. Defaults to `true`.
*
* - `fromSurface` : When true, captures screenshot
* {@link https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-captureScreenshot
* from the surface rather than the view}. When false, works only in
* headful mode and ignores page viewport (but not browser window's
* bounds). Defaults to `true`.
*
* NOTE: Screenshots take at least 1/6 second on OS X. See
* {@link https://crbug.com/741689} for discussion.
Expand Down Expand Up @@ -2768,9 +2783,10 @@ export class Page extends EventEmitter {
targetId: this._target._targetId,
});
let clip = options.clip ? processClip(options.clip) : undefined;
let { captureBeyondViewport = true } = options;
let { captureBeyondViewport = true, fromSurface = true } = options;
captureBeyondViewport =
typeof captureBeyondViewport === 'boolean' ? captureBeyondViewport : true;
fromSurface = typeof fromSurface === 'boolean' ? fromSurface : true;

if (options.fullPage) {
const metrics = await this._client.send('Page.getLayoutMetrics');
Expand Down Expand Up @@ -2810,6 +2826,7 @@ export class Page extends EventEmitter {
quality: options.quality,
clip,
captureBeyondViewport,
fromSurface,
});
if (shouldSetDefaultBackground) {
await this._resetDefaultBackgroundColor();
Expand Down

0 comments on commit bdfba51

Please sign in to comment.