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.
This commit is contained in:
Dmitry Gozman 2021-06-08 17:28:16 -07:00 committed by GitHub
parent 52e75cf13e
commit 6eeafc171b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {