diff --git a/types/puppeteer/index.d.ts b/types/puppeteer/index.d.ts index 5d30bf798a..e66ee97dfa 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 2db92a9171..1e3d35737b 100644 --- a/types/puppeteer/puppeteer-tests.ts +++ b/types/puppeteer/puppeteer-tests.ts @@ -397,3 +397,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(); +})();