From 6eeafc171b668c8562893c1b59a4abd61337bec6 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 8 Jun 2021 17:28:16 -0700 Subject: [PATCH] fix(chromium): fix a race when intialization does not finish before page close (#6975) This is exposed by the flaky "should report new window downloads" test. In this test a new page is created, initialized and closed before initialization finishes. If `lifecycleEventsEnabled` fails with "Target closed error", we correctly ignore the initialization failure, but a single usage of the failed promise with `.then` fails anyway. --- src/server/chromium/crPage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/chromium/crPage.ts b/src/server/chromium/crPage.ts index f54167df30..107537a1ed 100644 --- a/src/server/chromium/crPage.ts +++ b/src/server/chromium/crPage.ts @@ -482,7 +482,7 @@ class FrameSession { // 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). - lifecycleEventsEnabled.then(() => { + lifecycleEventsEnabled.catch(e => {}).then(() => { this._eventListeners.push(helper.addEventListener(this._client, 'Page.lifecycleEvent', event => this._onLifecycleEvent(event))); }); } else {