Merge pull request #28617 from ninoseki/update-puppeteer-definition

feat: update puppeteer definition
This commit is contained in:
Mine Starks
2018-09-05 08:36:04 -07:00
committed by GitHub
2 changed files with 17 additions and 1 deletions

View File

@@ -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<Buffer>;
screenshot(options?: ScreenshotOptions): Promise<string | Buffer>;
/**
* Triggers a `change` and `input` event once all the provided options have been selected.

View File

@@ -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();
})();