From b0d174fd9a860e399fb345dea8812833e1f3aecd Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 12 Nov 2020 16:13:55 -0800 Subject: [PATCH] revert: lifecycle refactoring, it breaks setContent (#4420) --- src/server/chromium/crPage.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/server/chromium/crPage.ts b/src/server/chromium/crPage.ts index 540692c823..be79388e45 100644 --- a/src/server/chromium/crPage.ts +++ b/src/server/chromium/crPage.ts @@ -397,8 +397,7 @@ class FrameSession { const { windowId } = await this._client.send('Browser.getWindowForTarget'); this._windowId = windowId; } - - let isInitialLifecycle = true; + let lifecycleEventsEnabled: Promise; if (!this._isMainFrame()) this._addRendererListeners(); this._addBrowserListeners(); @@ -421,22 +420,20 @@ class FrameSession { frame._evaluateExpression(binding.source, false, {}).catch(e => {}); } const isInitialEmptyPage = this._isMainFrame() && this._page.mainFrame().url() === ':'; - if (!isInitialEmptyPage) - this._firstNonInitialNavigationCommittedFulfill(); - this._eventListeners.push(helper.addEventListener(this._client, 'Page.lifecycleEvent', event => { + if (isInitialEmptyPage) { // Ignore lifecycle events for the initial empty page. It is never the final page // hence we are going to get more lifecycle updates after the actual navigation has // started (even if the target url is about:blank). - // Note: isInitialLifecycle is reset after the Page.setLifecycleEventsEnabled response. - const ignoreLifecycle = isInitialLifecycle && isInitialEmptyPage; - if (!ignoreLifecycle) - this._onLifecycleEvent(event); - })); + lifecycleEventsEnabled.then(() => { + this._eventListeners.push(helper.addEventListener(this._client, 'Page.lifecycleEvent', event => this._onLifecycleEvent(event))); + }); + } else { + this._firstNonInitialNavigationCommittedFulfill(); + this._eventListeners.push(helper.addEventListener(this._client, 'Page.lifecycleEvent', event => this._onLifecycleEvent(event))); + } }), this._client.send('Log.enable', {}), - this._client.send('Page.setLifecycleEventsEnabled', { enabled: true }).then(() => { - isInitialLifecycle = true; - }), + lifecycleEventsEnabled = this._client.send('Page.setLifecycleEventsEnabled', { enabled: true }), this._client.send('Runtime.enable', {}), this._client.send('Page.addScriptToEvaluateOnNewDocument', { source: sourceMap.generateSourceUrl(),