← Back to Discord Forum

waiting for video to save

Hi all. I'm trying to use Playwright to record instructional videos/screencasts. I'm really excited that I can record quality videos and use ghost-cursor for semi-realistic mouse movement and mouse-helper to draw a mouse and mouse clicks. I want to postprocess the video (to trim logging in, add voiceover/subtitles, etc.) in an afterEach hook. I'm not adept at JS async/await, but it seems like when I await page.video(), that awaits the existence of the video property but not the saving of the video. How can I wait for the video to be done saving?

This thread is trying to answer question "How can I wait for the video to be done saving in Playwright using JS async/await?"

0 replies


Waiting for Video Saving in Playwright

You can use the await keyword along with the video.saveAs() method in Playwright to wait for a video to finish saving. This method saves the video to a path you specify and waits until the page is closed and the video is fully saved.

Here's how you can do it:

const path = await page.video().path(); // Get the path where the video will be recorded

await page.video().saveAs(path); // Save the video to the path

console.log("Video has been saved.");

In this example, we first get the path where the video will be recorded using page.video().path(). Then, we save the video to that path using page.video().saveAs(path). The code will pause here until the video is fully saved.

Remember, you need to close both your browser context and page before trying to access or save any videos. Videos are only available after either the browser context or page is closed.

If you manually create a browser context, make sure to call browserContext.close() before trying to access or save any videos associated with that context.

The time it takes for Playwright to finish saving a video after calling video.saveAs() can vary. It's recommended to add appropriate waiting mechanisms or timeouts if necessary.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.