Skip to content

Commit d7d8e5b

Browse files
authored
Fix bidi screenshot quality=0 being treated as 80% (#39744)
1 parent bf1f743 commit d7d8e5b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/playwright-core/src/server/bidi/bidiPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ export class BidiPage implements PageDelegate {
480480
context: this._session.sessionId,
481481
format: {
482482
type: `image/${format === 'png' ? 'png' : 'jpeg'}`,
483-
quality: quality ? quality / 100 : 0.8,
483+
quality: quality !== undefined ? quality / 100 : undefined,
484484
},
485485
origin: documentRect ? 'document' : 'viewport',
486486
clip: {

tests/page/page-screenshot.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,13 @@ it.describe('page screenshot', () => {
394394
expect(error.message).toContain('options.quality is unsupported for the png');
395395
});
396396

397+
it('quality option should work for jpeg', async ({ page, server }) => {
398+
await page.goto(server.PREFIX + '/grid.html');
399+
const zeroQuality = await page.screenshot({ type: 'jpeg', quality: 0 });
400+
const highQuality = await page.screenshot({ type: 'jpeg', quality: 100 });
401+
expect(zeroQuality.byteLength).toBeLessThan(highQuality.byteLength);
402+
});
403+
397404
it('should prefer type over extension', async ({ page }, testInfo) => {
398405
const outputPath = testInfo.outputPath('file.png');
399406
const buffer = await page.screenshot({ path: outputPath, type: 'jpeg' });

0 commit comments

Comments
 (0)