fix(screencast): wait for ffmpeg to finish before reporting video (#6167)

This commit is contained in:
Yury Semikhatsky 2021-04-09 14:09:45 -07:00 committed by GitHub
parent 957abc49e9
commit f3b44d18be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 12 deletions

View File

@ -107,10 +107,10 @@ export abstract class Browser extends SdkObject {
}); });
} }
_videoFinished(videoId: string) { _takeVideo(videoId: string): Artifact | undefined {
const video = this._idToVideo.get(videoId); const video = this._idToVideo.get(videoId);
this._idToVideo.delete(videoId); this._idToVideo.delete(videoId);
video?.artifact.reportFinished(); return video?.artifact;
} }
_didClose() { _didClose() {

View File

@ -233,6 +233,14 @@ export abstract class BrowserContext extends SdkObject {
await this.instrumentation.onContextWillDestroy(this); await this.instrumentation.onContextWillDestroy(this);
// Cleanup.
const promises: Promise<void>[] = [];
for (const { context, artifact } of this._browser._idToVideo.values()) {
// Wait for the videos to finish.
if (context === this)
promises.push(artifact.finishedPromise());
}
if (this._isPersistentContext) { if (this._isPersistentContext) {
// Close all the pages instead of the context, // Close all the pages instead of the context,
// because we cannot close the default context. // because we cannot close the default context.
@ -242,13 +250,6 @@ export abstract class BrowserContext extends SdkObject {
await this._doClose(); await this._doClose();
} }
// Cleanup.
const promises: Promise<void>[] = [];
for (const { context, artifact } of this._browser._idToVideo.values()) {
// Wait for the videos to finish.
if (context === this)
promises.push(artifact.finishedPromise());
}
// We delete downloads after context closure // We delete downloads after context closure
// so that browser does not write to the download file anymore. // so that browser does not write to the download file anymore.
promises.push(this._deleteAllDownloads()); promises.push(this._deleteAllDownloads());

View File

@ -900,9 +900,10 @@ class FrameSession {
this._screencastId = null; this._screencastId = null;
const recorder = this._videoRecorder!; const recorder = this._videoRecorder!;
this._videoRecorder = null; this._videoRecorder = null;
const video = this._crPage._browserContext._browser._takeVideo(screencastId);
await this._stopScreencast(recorder); await this._stopScreencast(recorder);
await recorder.stop().catch(() => {}); await recorder.stop().catch(() => {});
this._crPage._browserContext._browser._videoFinished(screencastId); video?.reportFinished();
} }
async _startScreencast(client: any, options: Protocol.Page.startScreencastParameters = {}) { async _startScreencast(client: any, options: Protocol.Page.startScreencastParameters = {}) {

View File

@ -134,7 +134,7 @@ export class FFBrowser extends Browser {
} }
_onScreencastFinished(payload: Protocol.Browser.screencastFinishedPayload) { _onScreencastFinished(payload: Protocol.Browser.screencastFinishedPayload) {
this._videoFinished(payload.screencastId); this._takeVideo(payload.screencastId)?.reportFinished();
} }
} }

View File

@ -132,7 +132,7 @@ export class WKBrowser extends Browser {
} }
_onScreencastFinished(payload: Protocol.Playwright.screencastFinishedPayload) { _onScreencastFinished(payload: Protocol.Playwright.screencastFinishedPayload) {
this._videoFinished(payload.screencastId); this._takeVideo(payload.screencastId)?.reportFinished();
} }
_onPageProxyCreated(event: Protocol.Playwright.pageProxyCreatedPayload) { _onPageProxyCreated(event: Protocol.Playwright.pageProxyCreatedPayload) {