#24

Support JPEG format and quality in browser.screenshot()

Draftvercel[bot]wants to merge intofrom

Problem

browser.screenshot() can only produce PNG. At 2x DPR, a desktop viewport of an image-heavy page often produces a PNG over downstream size limits, such as a 3 MiB model-input limit. Vercel Agent's preview browser uses this library, and it had to fall back to exec('screenshot', { flags: { screenshotFormat: 'jpeg', screenshotQuality } }) to get a JPEG. agent-browser already supports --screenshot-format jpeg --screenshot-quality <0-100>, and exec() already returns that output as a .jpeg artifact.

Reproduction

On main (1.3.0), screenshot({ format: 'jpeg', quality: 70 }) ignores both options. It sends screenshot <tmp>.png with no format flags, and the result is labelled image/png. The new unit test captures JPEG screenshots with a quality and reports their content type fails on unmodified main (node --run test:unit: 3 of 44 failing) and passes with this change.

Fix

  • ScreenshotOptions gains format?: 'png' | 'jpeg' and quality?: number. quality must be an integer from 0 to 100 and only applies to JPEG; both are validated before any command runs.
  • screenshot() passes --screenshot-format and --screenshot-quality only when they're requested, so a default call sends exactly the same arguments as before.
  • The result now includes bytes, contentType and format.
    • PNG results keep png (the same Buffer), and type overloads keep png: Buffer for existing callers.
    • JPEG results leave png undefined, so JPEG bytes can't be mistaken for a PNG.
  • The README and the site describe the formats.

Verification

  • node --run test:unit passes (44/44), and so does node --run typecheck.
  • New tests cover the JPEG arguments and content type, the unchanged PNG result and arguments, and option validation.
  • Integration tests against a real Sandbox and Chromium weren't run in this environment.
  • Not fixed here, and older than this change: if client-wide arguments or AGENT_BROWSER_SCREENSHOT_FORMAT select JPEG, a plain screenshot() still labels the bytes as PNG. Passing format explicitly avoids this.

Created by Vercel Agent Factory.

Activity

2
vercel[bot]9d ago

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated
remote-agent-browser ReadyPreview, v0Nov 3, 2026 8:04pm UTC

This pull request is a draft

Merging is unavailable until it is marked ready for review.