Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webp to screenshot options #7565

Merged
merged 5 commits into from
Sep 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/common/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export interface ScreenshotOptions {
/**
* @defaultValue 'png'
*/
type?: 'png' | 'jpeg';
type?: 'png' | 'jpeg' | 'webp';
jschfflr marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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
Expand Down Expand Up @@ -2552,7 +2552,9 @@ export class Page extends EventEmitter {
// (i.e. as a temp file).
if (options.type) {
assert(
options.type === 'png' || options.type === 'jpeg',
options.type === 'png' ||
jschfflr marked this conversation as resolved.
Show resolved Hide resolved
options.type === 'jpeg' ||
options.type === 'webp',
'Unknown options.type value: ' + options.type
);
screenshotType = options.type;
Expand All @@ -2564,6 +2566,7 @@ export class Page extends EventEmitter {
if (extension === 'png') screenshotType = 'png';
else if (extension === 'jpg' || extension === 'jpeg')
screenshotType = 'jpeg';
else if (extension === 'webp') screenshotType = 'webp';
assert(
screenshotType,
`Unsupported screenshot type for extension \`.${extension}\``
Expand Down Expand Up @@ -2634,7 +2637,7 @@ export class Page extends EventEmitter {
}

private async _screenshotTask(
jschfflr marked this conversation as resolved.
Show resolved Hide resolved
format: 'png' | 'jpeg',
format: 'png' | 'jpeg' | 'webp',
options?: ScreenshotOptions
): Promise<Buffer | string> {
await this._client.send('Target.activateTarget', {
Expand Down