Skip to content

Commit

Permalink
fix: wait for ffmpeg to finish writing even if page was closed (micro…
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored May 19, 2021
1 parent e804d16 commit b946437
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/server/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
28 changes: 28 additions & 0 deletions tests/video.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});

0 comments on commit b946437

Please sign in to comment.