fix(screencast): replace ScreencastStopped with async path() (#3626)

This commit is contained in:
Yury Semikhatsky 2020-08-25 17:18:28 -07:00 committed by GitHub
parent 1a37f8ba7a
commit db0fa07330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 29 additions and 33 deletions

View File

@ -8,7 +8,7 @@
},
{
"name": "firefox",
"revision": "1166",
"revision": "1167",
"download": true
},
{

View File

@ -15,7 +15,7 @@
*/
import * as types from './types';
import { BrowserContext } from './browserContext';
import { BrowserContext, Screencast } from './browserContext';
import { Page } from './page';
import { EventEmitter } from 'events';
import { Download } from './download';
@ -47,6 +47,7 @@ export abstract class Browser extends EventEmitter {
private _downloads = new Map<string, Download>();
_defaultContext: BrowserContext | null = null;
private _startedClosing = false;
private readonly _idToScreencast = new Map<string, Screencast>();
constructor(options: BrowserOptions) {
super();
@ -85,6 +86,18 @@ export abstract class Browser extends EventEmitter {
this._downloads.delete(uuid);
}
_screencastStarted(screencastId: string, file: string, page: Page) {
const screencast = new Screencast(file, page);
this._idToScreencast.set(screencastId, screencast);
page._browserContext.emit(BrowserContext.Events.ScreencastStarted, screencast);
}
_screencastFinished(screencastId: string) {
const screencast = this._idToScreencast.get(screencastId);
this._idToScreencast.delete(screencastId);
screencast!._finishCallback();
}
_didClose() {
for (const context of this.contexts())
context._browserClosed();

View File

@ -66,7 +66,6 @@ export abstract class BrowserContext extends EventEmitter {
private _closePromiseFulfill: ((error: Error) => void) | undefined;
readonly _permissions = new Map<string, string[]>();
readonly _downloads = new Set<Download>();
readonly _idToScreencast = new Map<string, Screencast>();
readonly _browser: Browser;
readonly _browserContextId: string | undefined;

View File

@ -78,6 +78,7 @@ export class FFBrowser extends Browser {
helper.addEventListener(this._connection, 'Browser.detachedFromTarget', this._onDetachedFromTarget.bind(this)),
helper.addEventListener(this._connection, 'Browser.downloadCreated', this._onDownloadCreated.bind(this)),
helper.addEventListener(this._connection, 'Browser.downloadFinished', this._onDownloadFinished.bind(this)),
helper.addEventListener(this._connection, 'Browser.screencastFinished', this._onScreencastFinished.bind(this)),
];
}
@ -161,6 +162,10 @@ export class FFBrowser extends Browser {
const error = payload.canceled ? 'canceled' : payload.error;
this._downloadFinished(payload.uuid, error);
}
_onScreencastFinished(payload: Protocol.Browser.screencastFinishedPayload) {
this._screencastFinished(payload.screencastId);
}
}
export class FFBrowserContext extends BrowserContext {

View File

@ -32,7 +32,7 @@ import { FFNetworkManager } from './ffNetworkManager';
import { Protocol } from './protocol';
import { selectors } from '../selectors';
import { rewriteErrorMessage } from '../../utils/stackTrace';
import { Screencast, BrowserContext } from '../browserContext';
import { Screencast } from '../browserContext';
const UTILITY_WORLD_NAME = '__playwright_utility_world__';
@ -85,7 +85,6 @@ export class FFPage implements PageDelegate {
helper.addEventListener(this._session, 'Page.dispatchMessageFromWorker', this._onDispatchMessageFromWorker.bind(this)),
helper.addEventListener(this._session, 'Page.crashed', this._onCrashed.bind(this)),
helper.addEventListener(this._session, 'Page.screencastStarted', this._onScreencastStarted.bind(this)),
helper.addEventListener(this._session, 'Page.screencastStopped', this._onScreencastStopped.bind(this)),
];
this._pagePromise = new Promise(f => this._pageCallback = f);
session.once(FFSessionEvents.Disconnected, () => this._page._didDisconnect());
@ -260,15 +259,7 @@ export class FFPage implements PageDelegate {
}
_onScreencastStarted(event: Protocol.Page.screencastStartedPayload) {
const screencast = new Screencast(event.file, this._page);
this._idToScreencast.set(event.uid, screencast);
this._browserContext.emit(BrowserContext.Events.ScreencastStarted, screencast);
}
_onScreencastStopped(event: Protocol.Page.screencastStoppedPayload) {
const screencast = this._idToScreencast.get(event.uid);
this._idToScreencast.delete(event.uid);
screencast!._finishCallback();
this._browserContext._browser._screencastStarted(event.screencastId, event.file, this._page);
}
async exposeBinding(binding: PageBinding) {

View File

@ -65,6 +65,9 @@ export module Protocol {
canceled?: boolean;
error?: string;
}
export type screencastFinishedPayload = {
screencastId: string;
}
export type enableParameters = {
attachToDefaultContext: boolean;
};
@ -407,12 +410,9 @@ export module Protocol {
message: string;
}
export type screencastStartedPayload = {
uid: string;
screencastId: string;
file: string;
}
export type screencastStoppedPayload = {
uid: string;
}
export type closeParameters = {
runBeforeUnload?: boolean;
};
@ -931,6 +931,7 @@ export module Protocol {
"Browser.detachedFromTarget": Browser.detachedFromTargetPayload;
"Browser.downloadCreated": Browser.downloadCreatedPayload;
"Browser.downloadFinished": Browser.downloadFinishedPayload;
"Browser.screencastFinished": Browser.screencastFinishedPayload;
"Page.ready": Page.readyPayload;
"Page.crashed": Page.crashedPayload;
"Page.eventFired": Page.eventFiredPayload;
@ -951,7 +952,6 @@ export module Protocol {
"Page.workerDestroyed": Page.workerDestroyedPayload;
"Page.dispatchMessageFromWorker": Page.dispatchMessageFromWorkerPayload;
"Page.screencastStarted": Page.screencastStartedPayload;
"Page.screencastStopped": Page.screencastStoppedPayload;
"Runtime.executionContextCreated": Runtime.executionContextCreatedPayload;
"Runtime.executionContextDestroyed": Runtime.executionContextDestroyedPayload;
"Runtime.console": Runtime.consolePayload;

View File

@ -126,10 +126,7 @@ export class WKBrowser extends Browser {
}
_onScreencastFinished(payload: Protocol.Playwright.screencastFinishedPayload) {
const context = this._contexts.get(payload.browserContextId);
if (!context)
return;
context._screencastFinished(payload.screencastId);
this._screencastFinished(payload.screencastId);
}
_onPageProxyCreated(event: Protocol.Playwright.pageProxyCreatedPayload) {
@ -333,12 +330,6 @@ export class WKBrowserContext extends BrowserContext {
await (page._delegate as WKPage).updateRequestInterception();
}
_screencastFinished(uid: string) {
const screencast = this._idToScreencast.get(uid);
this._idToScreencast.delete(uid);
screencast!._finishCallback();
}
async _doClose() {
assert(this._browserContextId);
await this._browser._browserSession.send('Playwright.deleteContext', { browserContextId: this._browserContextId });

View File

@ -15,7 +15,6 @@
* limitations under the License.
*/
import { Screencast, BrowserContext } from '../browserContext';
import * as frames from '../frames';
import { helper, RegisteredListener } from '../helper';
import * as dom from '../dom';
@ -724,9 +723,7 @@ export class WKPage implements PageDelegate {
height: options.height,
scale: options.scale,
}) as any;
const screencast = new Screencast(options.outputFile, this._page);
this._browserContext._idToScreencast.set(screencastId, screencast);
this._browserContext.emit(BrowserContext.Events.ScreencastStarted, screencast);
this._browserContext._browser._screencastStarted(screencastId, options.outputFile, this._page);
} catch (e) {
this._recordingVideoFile = null;
throw e;