Skip to content

Commit 2be7574

Browse files
committed
fix: ignore quality for png
1 parent 9cb99ad commit 2be7574

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/tools/screenshot.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ export const screenshot = defineTool({
6262
pageOrHandle = context.getSelectedPage();
6363
}
6464

65+
const format = request.params.format;
66+
const quality = format === 'png' ? undefined : request.params.quality;
67+
6568
const screenshot = await pageOrHandle.screenshot({
66-
type: request.params.format,
69+
type: format,
6770
fullPage: request.params.fullPage,
68-
quality: request.params.quality,
71+
quality,
6972
optimizeForSpeed: true, // Bonus: optimize encoding for speed
7073
});
7174

tests/tools/screenshot.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ describe('screenshot', () => {
3030
);
3131
});
3232
});
33+
it('ignores quality', async () => {
34+
await withBrowser(async (response, context) => {
35+
const fixture = screenshots.basic;
36+
const page = context.getSelectedPage();
37+
await page.setContent(fixture.html);
38+
await screenshot.handler({params: {format: 'png', quality: 0}}, response, context);
39+
40+
assert.equal(response.images.length, 1);
41+
assert.equal(response.images[0].mimeType, 'image/png');
42+
assert.equal(
43+
response.responseLines.at(0),
44+
"Took a screenshot of the current page's viewport.",
45+
);
46+
});
47+
});
3348
it('with jpeg', async () => {
3449
await withBrowser(async (response, context) => {
3550
await screenshot.handler({params: {format: 'jpeg'}}, response, context);

0 commit comments

Comments
 (0)