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
ScreenshotOptionsgainsformat?: 'png' | 'jpeg'andquality?: number.qualitymust be an integer from 0 to 100 and only applies to JPEG; both are validated before any command runs.screenshot()passes--screenshot-formatand--screenshot-qualityonly when they're requested, so a default call sends exactly the same arguments as before.- The result now includes
bytes,contentTypeandformat.- PNG results keep
png(the same Buffer), and type overloads keeppng: Bufferfor existing callers. - JPEG results leave
pngundefined, so JPEG bytes can't be mistaken for a PNG.
- PNG results keep
- The README and the site describe the formats.
Verification
node --run test:unitpasses (44/44), and so doesnode --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_FORMATselect JPEG, a plainscreenshot()still labels the bytes as PNG. Passingformatexplicitly avoids this.
Created by Vercel Agent Factory.
Activity
2This pull request is a draft
Merging is unavailable until it is marked ready for review.
The latest updates on your projects. Learn more about Vercel for GitHub.