From 8ee19d53e7ebe4c114de32a4872156db8b9fd8a3 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 10 Jun 2020 13:36:45 -0700 Subject: [PATCH] feature(webkit): roll WebKit to 1273 (#2514) --- browsers.json | 2 +- src/server/webkit.ts | 49 ++++++++------------------------------ src/transport.ts | 2 +- src/webkit/wkBrowser.ts | 9 ++++--- src/webkit/wkConnection.ts | 2 +- 5 files changed, 17 insertions(+), 47 deletions(-) diff --git a/browsers.json b/browsers.json index 76b513bbf0..b890263ec9 100644 --- a/browsers.json +++ b/browsers.json @@ -10,7 +10,7 @@ }, { "name": "webkit", - "revision": "1269" + "revision": "1273" } ] } diff --git a/src/server/webkit.ts b/src/server/webkit.ts index b9c3065bd5..75db50400d 100644 --- a/src/server/webkit.ts +++ b/src/server/webkit.ts @@ -95,7 +95,6 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport, logger: Inne const pendingBrowserContextCreations = new Set(); const pendingBrowserContextDeletions = new Map(); const browserContextIds = new Map(); - const pageProxyIds = new Map(); const sockets = new Set(); transport.onmessage = message => { @@ -108,7 +107,7 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport, logger: Inne return; const { id, socket } = value; - if (socket.readyState === ws.CLOSING) { + if (socket.readyState === ws.CLOSED || socket.readyState === ws.CLOSING) { if (pendingBrowserContextCreations.has(id)) { transport.send({ id: ++SequenceNumberMixer._lastSequenceNumber, @@ -137,40 +136,16 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport, logger: Inne return; } - // Process notification response. - const { method, params, pageProxyId } = message; - if (pageProxyId) { - const socket = pageProxyIds.get(pageProxyId); - if (!socket || socket.readyState === ws.CLOSING) { - // Drop unattributed messages on the floor. - return; - } - socket.send(JSON.stringify(message)); - return; - } - if (method === 'Playwright.pageProxyCreated') { - const socket = browserContextIds.get(params.pageProxyInfo.browserContextId); - if (!socket || socket.readyState === ws.CLOSING) { - // Drop unattributed messages on the floor. - return; - } - pageProxyIds.set(params.pageProxyInfo.pageProxyId, socket); - socket.send(JSON.stringify(message)); - return; - } - if (method === 'Playwright.pageProxyDestroyed') { - const socket = pageProxyIds.get(params.pageProxyId); - pageProxyIds.delete(params.pageProxyId); - if (socket && socket.readyState !== ws.CLOSING) - socket.send(JSON.stringify(message)); - return; - } - if (method === 'Playwright.provisionalLoadFailed') { - const socket = pageProxyIds.get(params.pageProxyId); - if (socket && socket.readyState !== ws.CLOSING) - socket.send(JSON.stringify(message)); + // Every notification either has a browserContextId top-level field or + // has a browserContextId parameter. + const { params, browserContextId } = message; + const contextId = browserContextId || params.browserContextId; + const socket = browserContextIds.get(contextId); + if (!socket || socket.readyState === ws.CLOSING) { + // Drop unattributed messages on the floor. return; } + socket.send(JSON.stringify(message)); }; transport.onclose = () => { @@ -204,10 +179,6 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport, logger: Inne socket.on('error', logError(logger)); socket.on('close', (socket as any).__closeListener = () => { - for (const [pageProxyId, s] of pageProxyIds) { - if (s === socket) - pageProxyIds.delete(pageProxyId); - } for (const [browserContextId, s] of browserContextIds) { if (s === socket) { transport.send({ @@ -226,5 +197,5 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport, logger: Inne const wsEndpoint = typeof address === 'string' ? `${address}/${guid}` : `ws://127.0.0.1:${address.port}/${guid}`; return new WebSocketWrapper(wsEndpoint, - [pendingBrowserContextCreations, pendingBrowserContextDeletions, browserContextIds, pageProxyIds, sockets]); + [pendingBrowserContextCreations, pendingBrowserContextDeletions, browserContextIds, sockets]); } diff --git a/src/transport.ts b/src/transport.ts index 72d4e5b669..fb225146f9 100644 --- a/src/transport.ts +++ b/src/transport.ts @@ -26,7 +26,6 @@ export type ProtocolRequest = { method: string; params: any; sessionId?: string; - pageProxyId?: string; }; export type ProtocolResponse = { @@ -37,6 +36,7 @@ export type ProtocolResponse = { params?: any; result?: any; pageProxyId?: string; + browserContextId?: string; }; export interface ConnectionTransport { diff --git a/src/webkit/wkBrowser.ts b/src/webkit/wkBrowser.ts index a78fa75b6f..63902fcb95 100644 --- a/src/webkit/wkBrowser.ts +++ b/src/webkit/wkBrowser.ts @@ -124,15 +124,14 @@ export class WKBrowser extends BrowserBase { } _onPageProxyCreated(event: Protocol.Playwright.pageProxyCreatedPayload) { - const { pageProxyInfo } = event; - const pageProxyId = pageProxyInfo.pageProxyId; + const pageProxyId = event.pageProxyId; let context: WKBrowserContext | null = null; - if (pageProxyInfo.browserContextId) { + if (event.browserContextId) { // FIXME: we don't know about the default context id, so assume that all targets from // unknown contexts are created in the 'default' context which can in practice be represented // by multiple actual contexts in WebKit. Solving this properly will require adding context // lifecycle events. - context = this._contexts.get(pageProxyInfo.browserContextId) || null; + context = this._contexts.get(event.browserContextId) || null; } if (!context) context = this._defaultContext as WKBrowserContext; @@ -141,7 +140,7 @@ export class WKBrowser extends BrowserBase { const pageProxySession = new WKSession(this._connection, pageProxyId, `The page has been closed.`, (message: any) => { this._connection.rawSend({ ...message, pageProxyId }); }); - const opener = pageProxyInfo.openerId ? this._wkPages.get(pageProxyInfo.openerId) : undefined; + const opener = event.openerId ? this._wkPages.get(event.openerId) : undefined; const wkPage = new WKPage(context, pageProxySession, opener || null); this._wkPages.set(pageProxyId, wkPage); diff --git a/src/webkit/wkConnection.ts b/src/webkit/wkConnection.ts index 103970914f..bf495e437e 100644 --- a/src/webkit/wkConnection.ts +++ b/src/webkit/wkConnection.ts @@ -166,7 +166,7 @@ export class WKSession extends EventEmitter { callback.reject(createProtocolError(callback.error, callback.method, object.error)); else callback.resolve(object.result); - } else if (object.id) { + } else if (object.id && !object.error) { // Response might come after session has been disposed and rejected all callbacks. assert(this.isDisposed()); } else {