mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(webkit): band-aid double connection fix to unblock tests (#422)
This commit is contained in:
parent
85c0cc3ae2
commit
66e8a9c04f
@ -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();
|
||||
}
|
||||
|
||||
@ -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, {});
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user