From 63cc126805495871b712764f5b740bbfef277bf0 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Thu, 14 May 2020 15:43:23 -0700 Subject: [PATCH] fix(webkit): do not swallow init errors (#2242) This is a speculative fix to the following issue from the bots: NON-TEST ERROR #0: UNHANDLED ERROR TypeError: Cannot read property 'url' of undefined at WKPage._onTargetCreated (/Users/runner/runners/2.169.1/work/playwright/playwright/src/webkit/wkPage.ts:274:12) at process._tickCallback (internal/process/next_tick.js:68:7) I assume that _initializeSession did swallow an error, so we erroneously consider Page to be fully initialized (and having main frame). --- src/webkit/wkPage.ts | 8 +++++--- src/webkit/wkProvisionalPage.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/webkit/wkPage.ts b/src/webkit/wkPage.ts index 10db5b191573a..6f3552a73ead4 100644 --- a/src/webkit/wkPage.ts +++ b/src/webkit/wkPage.ts @@ -119,9 +119,11 @@ export class WKPage implements PageDelegate { // This method is called for provisional targets as well. The session passed as the parameter // may be different from the current session and may be destroyed without becoming current. - async _initializeSession(session: WKSession, resourceTreeHandler: (r: Protocol.Page.getResourceTreeReturnValue) => void) { + async _initializeSession(session: WKSession, provisional: boolean, resourceTreeHandler: (r: Protocol.Page.getResourceTreeReturnValue) => void) { await this._initializeSessionMayThrow(session, resourceTreeHandler).catch(e => { - if (session.isDisposed()) + // Provisional session can be disposed at any time, for example due to new navigation initiating + // a new provisional page. + if (provisional && session.isDisposed()) return; // Swallow initialization errors due to newer target swap in, // since we will reinitialize again. @@ -263,7 +265,7 @@ export class WKPage implements PageDelegate { this._setSession(session); await Promise.all([ this._initializePageProxySession(), - this._initializeSession(session, ({frameTree}) => this._handleFrameTree(frameTree)), + this._initializeSession(session, false, ({frameTree}) => this._handleFrameTree(frameTree)), ]); pageOrError = this._page; } catch (e) { diff --git a/src/webkit/wkProvisionalPage.ts b/src/webkit/wkProvisionalPage.ts index 86494a4650f4c..67f5842f63ecc 100644 --- a/src/webkit/wkProvisionalPage.ts +++ b/src/webkit/wkProvisionalPage.ts @@ -48,7 +48,7 @@ export class WKProvisionalPage { helper.addEventListener(session, 'Network.loadingFailed', overrideFrameId(e => wkPage._onLoadingFailed(e))), ]; - this.initializationPromise = this._wkPage._initializeSession(session, ({frameTree}) => this._handleFrameTree(frameTree)); + this.initializationPromise = this._wkPage._initializeSession(session, true, ({frameTree}) => this._handleFrameTree(frameTree)); } dispose() {