Skip to content

feat(screenshot): add webp output format#41152

Open
yury-s wants to merge 1 commit into
microsoft:mainfrom
yury-s:feat-screenshot-webp
Open

feat(screenshot): add webp output format#41152
yury-s wants to merge 1 commit into
microsoft:mainfrom
yury-s:feat-screenshot-webp

Conversation

@yury-s
Copy link
Copy Markdown
Member

@yury-s yury-s commented Jun 4, 2026

Summary

  • Adds webp to page.screenshot()/locator.screenshot() type union. Encoded natively via CDP (Chromium), Page.screenshot (Firefox), and Page.snapshotRect with format+quality (WebKit, which also drops the PNG→JPEG re-encode round-trip in Node).
  • Adds webp to the MCP browser_take_screenshot tool.

Fixes microsoft/playwright-mcp#1632

@yury-s yury-s requested a review from dgozman June 4, 2026 23:40
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.


try {
const quality = format === 'jpeg' ? options.quality ?? 80 : undefined;
const quality = format === 'jpeg' ? options.quality ?? 80 : format === 'webp' ? options.quality : undefined;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No default quality for webp?

@yury-s
Copy link
Copy Markdown
Member Author

yury-s commented Jun 5, 2026

WebP on macOS WebKit is skipped.

The WebKit protocol patch (browser_patches/webkit via playwright-browsers#2281) is in revision 2302, but macOS's CGImageDestination does not advertise a webp encoder UTI. So Page.snapshotRect with format: webp returns data:, (empty) on macOS WebKit even though jpeg and png work fine.

Verified with this Swift script on macOS 26.5:

import CoreServices
import ImageIO
import UniformTypeIdentifiers

if let types = CGImageDestinationCopyTypeIdentifiers() as? [String] {
    print("Image destination UTIs:")
    for t in types where t.lowercased().contains("webp") || t.lowercased().contains("jpeg") || t.lowercased().contains("png") {
        print("  \(t)")
    }
}

Output:

Image destination UTIs:
  public.jpeg
  public.png
  public.jpeg-2000

No public.webp. The WebKit-side MIMETypeRegistry::isSupportedImageMIMETypeForEncoding for COCOA is populated from this list, so the encoder silently no-ops. Linux WebKit (Skia) does have a webp encoder, so those tests still run. Skipping the three webp tests for macOS WebKit until Apple ships a CG webp encoder (or WebKit builds with Skia on macOS).

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Adds `webp` to the screenshot type union for `page.screenshot()`,
`locator.screenshot()`, the MCP `browser_take_screenshot` tool, and
the playwright-cli `screenshot` command. Encoded natively by each
browser — CDP for Chromium, `Page.screenshot` for Firefox, and
`Page.snapshotRect` (with format + quality) for WebKit; the WebKit
path also drops the PNG→JPEG re-encode round-trip in Node.

The MCP/CLI tools infer the format from the filename extension when
`type` is unset. The CLI help generator now lists enum choices for
any `z.enum` option.

WebP screenshots are not supported in WebKit on macOS because
CoreGraphics does not ship a webp encoder UTI; the WebKit delegate
throws a clear error there.

Fixes microsoft/playwright-mcp#1632
@yury-s yury-s force-pushed the feat-screenshot-webp branch from 3871415 to e061865 Compare June 5, 2026 17:32
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Test results for "MCP"

7290 passed, 1121 skipped


Merge workflow run.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Test results for "tests 1"

2 flaky ⚠️ [chromium-library] › library/browsertype-connect.spec.ts:699 › run-server › should record trace with sources `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/page-close.spec.ts:152 › should not treat navigations as new popups `@chromium-ubuntu-22.04-node24`

39525 passed, 775 skipped


Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add screenshot output format option (PNG/JPEG/WebP)

3 participants