diff --git a/types/puppeteer/index.d.ts b/types/puppeteer/index.d.ts index e66ee97dfa..eab93cf2eb 100644 --- a/types/puppeteer/index.d.ts +++ b/types/puppeteer/index.d.ts @@ -592,6 +592,14 @@ export interface ScreenshotOptions { encoding?: "base64" | "binary"; } +export interface BinaryScreenShotOptions extends ScreenshotOptions { + encoding?: "binary"; +} + +export interface Base64ScreenShotOptions extends ScreenshotOptions { + encoding: "base64"; +} + /** Options for `addStyleTag` */ export interface StyleTagOptions { /** Url of the tag. */ @@ -747,7 +755,9 @@ export interface ElementHandle extends JSHandle, Ev * If the element is detached from DOM, the method throws an error. * @param options Same options as in page.screenshot. */ - screenshot(options?: ScreenshotOptions): Promise; + screenshot(options?: Base64ScreenShotOptions): Promise; + screenshot(options?: BinaryScreenShotOptions): Promise; + screenshot(options?: ScreenshotOptions): Promise; /** * This method scrolls element into view if needed, and then uses touchscreen.tap to tap in the center of the element. * If the element is detached from DOM, the method throws an error. @@ -1346,6 +1356,8 @@ export interface Page extends EventEmitter, FrameBase { * Captures a screenshot of the page. * @param options The screenshot options. */ + screenshot(options?: Base64ScreenShotOptions): Promise; + screenshot(options?: BinaryScreenShotOptions): Promise; screenshot(options?: ScreenshotOptions): Promise; /** diff --git a/types/puppeteer/puppeteer-tests.ts b/types/puppeteer/puppeteer-tests.ts index 1e3d35737b..fb0c283d4b 100644 --- a/types/puppeteer/puppeteer-tests.ts +++ b/types/puppeteer/puppeteer-tests.ts @@ -403,8 +403,12 @@ puppeteer.launch().then(async browser => { 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; + const base64string: string = await page.screenshot({ encoding: "base64" }); + const buffer: Buffer = await page.screenshot({ encoding: "binary" }); + const screenshotOptions: puppeteer.ScreenshotOptions = { + fullPage: true, + }; + const stringOrBuffer: string | Buffer = await page.screenshot(screenshotOptions); browser.close(); })();