Skip to content

Commit

Permalink
feature(webkit): roll WebKit to 1273 (#2514)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Jun 10, 2020
1 parent d7f867d commit 8ee19d5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 47 deletions.
2 changes: 1 addition & 1 deletion browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"name": "webkit",
"revision": "1269"
"revision": "1273"
}
]
}
49 changes: 10 additions & 39 deletions src/server/webkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport, logger: Inne
const pendingBrowserContextCreations = new Set<number>();
const pendingBrowserContextDeletions = new Map<number, string>();
const browserContextIds = new Map<string, ws>();
const pageProxyIds = new Map<string, ws>();
const sockets = new Set<ws>();

transport.onmessage = message => {
Expand All @@ -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,
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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({
Expand All @@ -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]);
}
2 changes: 1 addition & 1 deletion src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export type ProtocolRequest = {
method: string;
params: any;
sessionId?: string;
pageProxyId?: string;
};

export type ProtocolResponse = {
Expand All @@ -37,6 +36,7 @@ export type ProtocolResponse = {
params?: any;
result?: any;
pageProxyId?: string;
browserContextId?: string;
};

export interface ConnectionTransport {
Expand Down
9 changes: 4 additions & 5 deletions src/webkit/wkBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/webkit/wkConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8ee19d5

Please sign in to comment.