Skip to content

Commit 2eaf268

Browse files
authored
fix: ignore quality for png (#589)
Fixes #588
1 parent 9cb99ad commit 2eaf268

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ 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(
39+
{params: {format: 'png', quality: 0}},
40+
response,
41+
context,
42+
);
43+
44+
assert.equal(response.images.length, 1);
45+
assert.equal(response.images[0].mimeType, 'image/png');
46+
assert.equal(
47+
response.responseLines.at(0),
48+
"Took a screenshot of the current page's viewport.",
49+
);
50+
});
51+
});
3352
it('with jpeg', async () => {
3453
await withBrowser(async (response, context) => {
3554
await screenshot.handler({params: {format: 'jpeg'}}, response, context);

0 commit comments

Comments
 (0)