Skip to content

fix(screencast): auto-save video when page closes without stop#41744

Open
sarang-code2 wants to merge 1 commit into
microsoft:mainfrom
sarang-code2:fix/screencast-auto-save-on-page-close
Open

fix(screencast): auto-save video when page closes without stop#41744
sarang-code2 wants to merge 1 commit into
microsoft:mainfrom
sarang-code2:fix/screencast-auto-save-on-page-close

Conversation

@sarang-code2

Copy link
Copy Markdown

Closes #41608

Problem

When using page.screencast.start({ path: 'video.webm' }), if the page closes before page.screencast.stop() is called, the video file is never saved to disk. The server already stops the recording gracefully, but the client never calls artifact.saveAs() to write the file.

This makes it impossible to record a video showing "the window closing when a button is pressed."

Solution

Listen for Events.Page.Close in the client-side Screencast constructor. When the page closes while a recording is active (with a path option), automatically save the artifact to the specified path.

Changes:

  • packages/playwright-core/src/client/screencast.ts — Register a one-time Page.Close listener that auto-saves the artifact
  • tests/library/screencast.spec.ts — Add test verifying auto-save on page close

Usage

await page.screencast.start({ path: 'video.webm' });
await page.getByRole('button', { name: 'close' }).click(); // closes the page
// video.webm is now automatically saved!

When using page.screencast.start({ path }), if the page closes before
stop() is called, the video file was never saved. The server already
stops the recording gracefully, but the client never called
artifact.saveAs().

Listen for Events.Page.Close in the client Screencast constructor and
auto-save the artifact when the page closes while a recording is active.

Fixes microsoft#41608
@sarang-code2

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Automatically stop the screencast video recording and save the video file when the page is closed.

1 participant