Skip to content

Commit 5dc7b5a

Browse files
aberemia24OrKoN
authored andcommitted
feat(screenshot): add JPEG quality parameter support
- Add optional quality parameter (0-100) to screenshot schema - Pass quality parameter to Puppeteer screenshot method - Add optimizeForSpeed flag for improved performance - Update documentation with new parameter details This allows users to control JPEG compression quality, significantly reducing file sizes for screenshots. For example, quality=50 can reduce file size by ~35% compared to PNG format. Fixes potential issues with large screenshot sizes exceeding API limits when using Chrome DevTools MCP with AI assistants.
1 parent 1f4007e commit 5dc7b5a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

docs/tool-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ so returned values have to JSON-serializable.
308308

309309
- **format** (enum: "png", "jpeg") _(optional)_: Type of format to save the screenshot as. Default is "png"
310310
- **fullPage** (boolean) _(optional)_: If set to true takes a screenshot of the full page instead of the currently visible viewport. Incompatible with uid.
311+
- **quality** (number) _(optional)_: Compression quality for JPEG format (0-100). Higher values mean better quality but larger file sizes. Ignored for PNG format.
311312
- **uid** (string) _(optional)_: The uid of an element on the page from the page content snapshot. If omitted takes a pages screenshot.
312313

313314
---

src/tools/screenshot.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ export const screenshot = defineTool({
2222
.enum(['png', 'jpeg'])
2323
.default('png')
2424
.describe('Type of format to save the screenshot as. Default is "png"'),
25+
quality: z
26+
.number()
27+
.min(0)
28+
.max(100)
29+
.optional()
30+
.describe(
31+
'Compression quality for JPEG format (0-100). Higher values mean better quality but larger file sizes. Ignored for PNG format.',
32+
),
2533
uid: z
2634
.string()
2735
.optional()
@@ -50,6 +58,8 @@ export const screenshot = defineTool({
5058
const screenshot = await pageOrHandle.screenshot({
5159
type: request.params.format,
5260
fullPage: request.params.fullPage,
61+
quality: request.params.quality,
62+
optimizeForSpeed: true, // Bonus: optimize encoding for speed
5363
});
5464

5565
if (request.params.uid) {

0 commit comments

Comments
 (0)