Skip to main content
Version: 1.12.0

Videos

Playwright can record videos for all pages in a browser context. Videos are saved upon context closure, so make sure to await BrowserContext.CloseAsync().

var context = await browser.NewContextAsync(new BrowserNewContextOptions
{
RecordVideoDir = "videos/"
});
// Make sure to close, so that videos are saved.
await context.CloseAsync();

You can also specify video size, it defaults to viewport size scaled down to fit 800x800.

var context = await browser.NewContextAsync(new BrowserNewContextOptions
{
RecordVideoDir = "videos/",
RecordVideoSize = new RecordVideoSize() { Width = 640, Height = 480 }
});
// Make sure to close, so that videos are saved.
await context.CloseAsync();

Saved video files will appear in the specified folder. They all have generated unique names. For the multi-page scenarios, you can access the video file associated with the page via the Page.Video.

var path = await page.Video.PathAsync();
note

Note that the video is only available after the page or browser context is closed.

API reference#