From c11297baa5124eb89f7686c3eb446d2ba1b7123a Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Fri, 28 Oct 2022 09:56:06 +0200 Subject: [PATCH] fix: resolve navigation requests when request fails (#9178) #8768 fixes flakiness in handling navigations but it didn't account for the fact that subsequent navigation requests could be aborted via the request interception. In that case, the navigationResponseReceived promise would never be resolved. This PR adds a listener for the failed network requests and resolves the promise if the network request has failed. Adding test coverage for this seems tricky, as the reproduction depends on timing of the second navigation request. Closes #9175 --- .../puppeteer-core/src/common/LifecycleWatcher.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/puppeteer-core/src/common/LifecycleWatcher.ts b/packages/puppeteer-core/src/common/LifecycleWatcher.ts index b68e22dcd4e96..fef7bfc1ab5af 100644 --- a/packages/puppeteer-core/src/common/LifecycleWatcher.ts +++ b/packages/puppeteer-core/src/common/LifecycleWatcher.ts @@ -168,6 +168,11 @@ export class LifecycleWatcher { NetworkManagerEmittedEvents.Response, this.#onResponse.bind(this) ), + addEventListener( + this.#frameManager.networkManager, + NetworkManagerEmittedEvents.RequestFailed, + this.#onRequestFailed.bind(this) + ), ]; this.#timeoutPromise = this.#createTimeoutPromise(); @@ -189,6 +194,13 @@ export class LifecycleWatcher { } } + #onRequestFailed(request: HTTPRequest): void { + if (this.#navigationRequest?._requestId !== request._requestId) { + return; + } + this.#navigationResponseReceived?.resolve(); + } + #onResponse(response: HTTPResponse): void { if (this.#navigationRequest?._requestId !== response.request()._requestId) { return;