Skip to content

Commit

Permalink
fix: resolve navigation requests when request fails (#9178)
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
OrKoN committed Oct 28, 2022
1 parent 2d2120c commit c11297b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/puppeteer-core/src/common/LifecycleWatcher.ts
Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit c11297b

Please sign in to comment.