From b786d56fd6b99ba3f0082241e38124a85a81d8db Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Tue, 4 Sep 2018 16:37:25 +0900 Subject: [PATCH] feat: update puppeteer definition `encoding` option in `page.screenshot` method is missing so I add it to the definition. https://github.com/GoogleChrome/puppeteer/blob/v1.7.0/docs/api.md#pagescreenshotoptions --- types/puppeteer/index.d.ts | 7 ++++++- types/puppeteer/puppeteer-tests.ts | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/types/puppeteer/index.d.ts b/types/puppeteer/index.d.ts index 5f62134c90..4a99034e23 100644 --- a/types/puppeteer/index.d.ts +++ b/types/puppeteer/index.d.ts @@ -585,6 +585,11 @@ export interface ScreenshotOptions { * @default false */ omitBackground?: boolean; + /** + * The encoding of the image, can be either base64 or binary. Defaults to binary + * @default binary + */ + encoding?: "base64" | "binary"; } /** Options for `addStyleTag` */ @@ -1341,7 +1346,7 @@ export interface Page extends EventEmitter, FrameBase { * Captures a screenshot of the page. * @param options The screenshot options. */ - screenshot(options?: ScreenshotOptions): Promise; + screenshot(options?: ScreenshotOptions): Promise; /** * Triggers a `change` and `input` event once all the provided options have been selected. diff --git a/types/puppeteer/puppeteer-tests.ts b/types/puppeteer/puppeteer-tests.ts index e883157fec..9595776600 100644 --- a/types/puppeteer/puppeteer-tests.ts +++ b/types/puppeteer/puppeteer-tests.ts @@ -396,3 +396,14 @@ puppeteer.launch().then(async browser => { ); index; // $ExpectType number }); + +// Test screenshot with an encoding option +(async () => { + const browser = await puppeteer.launch(); + const page = await browser.newPage(); + await page.goto("https://example.com"); + const base64string: string = (await page.screenshot({ encoding: "base64" })) as string; + const buffer: Buffer = (await page.screenshot({ encoding: "binary" })) as Buffer; + + browser.close(); +})();