From 6219042c74eb638489ea00a1d1db68a1b7580057 Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Mon, 3 May 2021 12:34:09 -0700 Subject: [PATCH] fix(webkit): swallow requests from detached frames (#6242) --- src/server/webkit/wkPage.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/server/webkit/wkPage.ts b/src/server/webkit/wkPage.ts index 8c5b615f822fa..bc64fb44cf8ec 100644 --- a/src/server/webkit/wkPage.ts +++ b/src/server/webkit/wkPage.ts @@ -898,7 +898,12 @@ export class WKPage implements PageDelegate { redirectedFrom = request.request; } } - const frame = this._page._frameManager.frame(event.frameId)!; + const frame = redirectedFrom ? redirectedFrom.frame() : this._page._frameManager.frame(event.frameId); + // sometimes we get stray network events for detached frames + // TODO(einbinder) why? + if (!frame) + return; + // TODO(einbinder) this will fail if we are an XHR document request const isNavigationRequest = event.type === 'Document'; const documentId = isNavigationRequest ? event.loaderId : undefined; @@ -919,8 +924,10 @@ export class WKPage implements PageDelegate { _onRequestIntercepted(event: Protocol.Network.requestInterceptedPayload) { const request = this._requestIdToRequest.get(event.requestId); - if (!request) + if (!request) { + this._session.sendMayFail('Network.interceptRequestWithError', {errorType: 'Cancellation', requestId: event.requestId}); return; + } if (!request._allowInterception) { // Intercepted, although we do not intend to allow interception. // Just continue.