From 87aaed4807e5240dec7b25273e44c1ce5e884336 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Mon, 3 Jul 2023 11:43:34 +0200 Subject: [PATCH] feat(screenshot): enable optimizeForSpeed (#10492) --- docs/api/puppeteer.screenshotoptions.md | 1 + packages/puppeteer-core/src/api/Page.ts | 4 ++++ packages/puppeteer-core/src/common/Page.ts | 1 + 3 files changed, 6 insertions(+) diff --git a/docs/api/puppeteer.screenshotoptions.md b/docs/api/puppeteer.screenshotoptions.md index 784e37b6c3a..47470e8499d 100644 --- a/docs/api/puppeteer.screenshotoptions.md +++ b/docs/api/puppeteer.screenshotoptions.md @@ -20,6 +20,7 @@ export interface ScreenshotOptions | fromSurface | optional | boolean | Capture the screenshot from the surface, rather than the view. | true | | fullPage | optional | boolean | When true, takes a screenshot of the full page. | false | | omitBackground | optional | boolean | Hides default white background and allows capturing screenshots with transparency. | false | +| optimizeForSpeed | optional | boolean | | false | | path | optional | string | The file path to save the image to. The screenshot type will be inferred from file extension. If path is a relative path, then it is resolved relative to current working directory. If no path is provided, the image won't be saved to the disk. | | | quality | optional | number | Quality of the image, between 0-100. Not applicable to png images. | | | type | optional | 'png' \| 'jpeg' \| 'webp' | | png | diff --git a/packages/puppeteer-core/src/api/Page.ts b/packages/puppeteer-core/src/api/Page.ts index 60e2f0438fd..c70ae773fd4 100644 --- a/packages/puppeteer-core/src/api/Page.ts +++ b/packages/puppeteer-core/src/api/Page.ts @@ -170,6 +170,10 @@ export interface ScreenshotClip { * @public */ export interface ScreenshotOptions { + /** + * @defaultValue `false` + */ + optimizeForSpeed?: boolean; /** * @defaultValue `png` */ diff --git a/packages/puppeteer-core/src/common/Page.ts b/packages/puppeteer-core/src/common/Page.ts index 99eecb8f117..2c7b45f143e 100644 --- a/packages/puppeteer-core/src/common/Page.ts +++ b/packages/puppeteer-core/src/common/Page.ts @@ -1267,6 +1267,7 @@ export class CDPPage extends Page { const result = await this.#client.send('Page.captureScreenshot', { format, + optimizeForSpeed: options.optimizeForSpeed, quality: options.quality, clip: clip && { ...clip,