fix: wait for ffmpeg to finish writing even if page was closed (#6648)

This commit is contained in:
Yury Semikhatsky 2021-05-19 05:29:39 +00:00 committed by GitHub
parent e804d16dce
commit b94643786b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -900,9 +900,11 @@ class FrameSession {
this._screencastId = null;
const recorder = this._videoRecorder!;
this._videoRecorder = null;
const video = this._crPage._browserContext._browser._takeVideo(screencastId);
await this._stopScreencast(recorder);
await recorder.stop().catch(() => {});
// Keep the video artifact in the map utntil encoding is fully finished, if the context
// starts closing before the video is fully written to disk it will wait for it.
const video = this._crPage._browserContext._browser._takeVideo(screencastId);
video?.reportFinished();
}

View file

@ -615,4 +615,32 @@ it.describe('screencast', () => {
const saveResult = await page.video().saveAs(file).catch(e => e);
expect(saveResult.message).toContain('rowser has been closed');
});
it('should wait for video to finish if page was closed', async ({browserType, browserOptions, contextOptions}, testInfo) => {
const size = { width: 320, height: 240 };
const browser = await browserType.launch(browserOptions);
const videoDir = testInfo.outputPath('');
const context = await browser.newContext({
...contextOptions,
recordVideo: {
dir: videoDir,
size,
},
viewport: size,
});
const page = await context.newPage();
await new Promise(r => setTimeout(r, 1000));
await page.close();
await context.close();
await browser.close();
const videoFiles = findVideos(videoDir);
expect(videoFiles.length).toBe(1);
const videoPlayer = new VideoPlayer(videoFiles[0]);
expect(videoPlayer.videoWidth).toBe(320);
expect(videoPlayer.videoHeight).toBe(240);
});
});