fix(webkit): band-aid double connection fix to unblock tests (#422)

This commit is contained in:
Dmitry Gozman 2020-01-08 07:13:51 -08:00 committed by Yury Semikhatsky
parent 85c0cc3ae2
commit 66e8a9c04f
3 changed files with 13 additions and 2 deletions

View File

@ -67,7 +67,7 @@ export class WKBrowserServer {
async close(): Promise<void> {
const transport = await createTransport(this._connectOptions);
const connection = new WKConnection(transport);
const connection = WKConnection.from(transport);
await connection.send('Browser.close');
connection.dispose();
}

View File

@ -51,7 +51,7 @@ export class WKBrowser extends browser.Browser {
constructor(transport: ConnectionTransport) {
super();
this._connection = new WKConnection(transport);
this._connection = WKConnection.from(transport);
this._defaultContext = this._createBrowserContext(undefined, {});

View File

@ -34,6 +34,8 @@ export const WKPageProxySessionEvents = {
DidCommitProvisionalTarget: Symbol('PageProxyEvents.DidCommitProvisionalTarget'),
};
const kConnectionSymbol = Symbol();
export class WKConnection extends platform.EventEmitter {
private _lastId = 0;
private readonly _callbacks = new Map<number, {resolve:(o: any) => void, reject: (e: Error) => void, error: Error, method: string}>();
@ -42,6 +44,15 @@ export class WKConnection extends platform.EventEmitter {
private _closed = false;
static from(transport: ConnectionTransport): WKConnection {
let connection = (transport as any)[kConnectionSymbol];
if (!connection) {
connection = new WKConnection(transport);
(transport as any)[kConnectionSymbol] = connection;
}
return connection;
}
constructor(transport: ConnectionTransport) {
super();
this._transport = transport;