🎬 Save a video recording of a Playwright page (Chromium only for now)
When Playwright adds support for the Screencast API in Firefox and WebKit, this will be updated to support these browsers.
npm i playwright playwright-video ffmpeg-static
If you already have FFmpeg installed, you can skip the ffmpeg-static
installation by setting the FFMPEG_PATH
environment variable.
npm i playwright playwright-video
const { chromium } = require('playwright');
const { saveVideo } = require('playwright-video');
(async () => {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await saveVideo(page, '/tmp/video.mp4');
await page.goto('http://example.org');
await page.click('a');
await browser.close();
})();
The video will be saved at the specified savePath
(/tmp/video.mp4
in the above example).
page
<Page> Save a video of this page. Only supports Chromium for now.savePath
<string> Where to save the video.- returns: <Promise<PageVideoCapture>>
Records video of a page and saves it at the specified path.
await saveVideo(page, '/tmp/video.mp4');
A PageVideoCapture
is created when you call saveVideo
. It manages capturing the video of your page and saving it.
- returns <Promise>
Stop the video capture if needed and save the video. The returned Promise
resolves when the video is saved.
The video capture will be stopped automatically if you close the page, so you should not need to call this unless you want to explicitly wait until the video is saved.
const capture = await saveVideo(page, '/tmp/video.mp4');
await capture.stop();