Skip to content

Commit

Permalink
fix: wait for video to finish when persistent context closes (microso…
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed May 19, 2021
1 parent e679d99 commit 2ef47b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/server/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { RecentLogsCollector } from '../utils/debugLogger';
import * as registry from '../utils/registry';
import { SdkObject } from './instrumentation';
import { Artifact } from './artifact';
import { kBrowserClosedError } from '../utils/errors';

export interface BrowserProcess {
onclose?: ((exitCode: number | null, signal: string | null) => void);
Expand Down Expand Up @@ -120,9 +119,6 @@ export abstract class Browser extends SdkObject {
context._browserClosed();
if (this._defaultContext)
this._defaultContext._browserClosed();
for (const video of this._idToVideo.values())
video.artifact.reportFinished(kBrowserClosedError);
this._idToVideo.clear();
this.emit(Browser.Events.Disconnected);
}

Expand Down
10 changes: 9 additions & 1 deletion src/server/firefox/ffBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import { kBrowserClosedError } from '../../utils/errors';
import { assert } from '../../utils/utils';
import { Browser, BrowserOptions } from '../browser';
import { assertBrowserContextIsNotOwned, BrowserContext, validateBrowserContextOptions, verifyGeolocation } from '../browserContext';
Expand Down Expand Up @@ -56,7 +57,7 @@ export class FFBrowser extends Browser {
this._connection = connection;
this._ffPages = new Map();
this._contexts = new Map();
this._connection.on(ConnectionEvents.Disconnected, () => this._didClose());
this._connection.on(ConnectionEvents.Disconnected, () => this._onDisconnect());
this._connection.on('Browser.attachedToTarget', this._onAttachedToTarget.bind(this));
this._connection.on('Browser.detachedFromTarget', this._onDetachedFromTarget.bind(this));
this._connection.on('Browser.downloadCreated', this._onDownloadCreated.bind(this));
Expand Down Expand Up @@ -136,6 +137,13 @@ export class FFBrowser extends Browser {
_onVideoRecordingFinished(payload: Protocol.Browser.videoRecordingFinishedPayload) {
this._takeVideo(payload.screencastId)?.reportFinished();
}

_onDisconnect() {
for (const video of this._idToVideo.values())
video.artifact.reportFinished(kBrowserClosedError);
this._idToVideo.clear();
this._didClose();
}
}

export class FFBrowserContext extends BrowserContext {
Expand Down
4 changes: 4 additions & 0 deletions src/server/webkit/wkBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as types from '../types';
import { Protocol } from './protocol';
import { kPageProxyMessageReceived, PageProxyMessageReceivedPayload, WKConnection, WKSession } from './wkConnection';
import { WKPage } from './wkPage';
import { kBrowserClosedError } from '../../utils/errors';

const DEFAULT_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.2 Safari/605.1.15';
const BROWSER_VERSION = '14.2';
Expand Down Expand Up @@ -72,6 +73,9 @@ export class WKBrowser extends Browser {
_onDisconnect() {
for (const wkPage of this._wkPages.values())
wkPage.dispose(true);
for (const video of this._idToVideo.values())
video.artifact.reportFinished(kBrowserClosedError);
this._idToVideo.clear();
this._didClose();
}

Expand Down

0 comments on commit 2ef47b9

Please sign in to comment.