Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/src/api/class-screencast.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ The quality of the image, between 0-100.
- `height` <[int]> Max frame height in pixels.

Specifies the dimensions of screencast frames. The actual frame is scaled to preserve the page's aspect ratio and may be smaller than these bounds.
If a screencast is already active (e.g. started by tracing or video recording), the existing configuration takes precedence and the frame size may exceed these bounds or this option may be ignored.
If not specified the size will be equal to page viewport scaled down to fit into 800×800.

A page is captured only once, and all consumers share that single capture. Tracing captures screenshots
this way as well, so with tracing or the `recordVideo` context option already active this option is
ignored, and both the frames and any recorded video use the size of the running capture.

## async method: Screencast.stop
* since: v1.59

Expand Down
7 changes: 4 additions & 3 deletions packages/playwright-core/src/server/videoRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ export class VideoRecorder {
size: options.size,
};

// Encode into the size of the running capture: it may differ from the requested one when
// another client (e.g. tracing) started the screencast first, and padding a smaller frame
// into the requested size would leave gray borders.
const { size } = this._screencast.addClient(this._client);
// For video files only, prioritize encoding into the given size, regardless of the actual pixel data.
const videoSize = options.size ?? size;
this._videoRecorder = new FfmpegVideoRecorder(ffmpegPath, videoSize, outputFile, this._screencast.page.delegate);
this._videoRecorder = new FfmpegVideoRecorder(ffmpegPath, size, outputFile, this._screencast.page.delegate);
Comment thread
yury-s marked this conversation as resolved.
Resolved
this._artifact = new Artifact(this._screencast.page.browserContext, outputFile);
return this._artifact;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/library/screencast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,27 @@ test('start dispose stops recording', async ({ browser }, testInfo) => {
await context.close();
});

test('start size is ignored while tracing is active', async ({ browser, trace }, testInfo) => {
test.skip(trace === 'on', 'the test starts its own tracing');
test.slow();

const context = await browser.newContext({ viewport: { width: 1600, height: 1200 } });
await context.tracing.start({ screenshots: true });
const page = await context.newPage();

const videoPath = testInfo.outputPath('video.webm');
// Tracing already captures at the viewport scaled down to 800x600, so this size is ignored.
await page.screencast.start({ path: videoPath, size: { width: 1000, height: 750 } });
await page.evaluate(() => document.body.style.backgroundColor = 'red');
await ensureSomeFrames(page);
await page.screencast.stop();

await context.tracing.stop();
await context.close();
// The video must fill its frame rather than pad the smaller capture with gray.
expectRedFrames(videoPath, { width: 800, height: 600 });
});

type Pixel = { r: number, g: number, b: number, alpha: number };
type PixelPredicate = (pixel: Pixel) => boolean;

Expand Down
Loading