Skip to content

Commit

Permalink
fix: resolve navigation requests when request fails
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Oct 28, 2022
1 parent 9e95774 commit 0049f27
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 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 @@ -179,16 +184,22 @@ export class LifecycleWatcher {
return;
}
this.#navigationRequest = request;
// Resolve previous navigation response in case there are multiple
// navigation requests reported by the backend. This generally should not
// happen by it looks like it's possible.
this.#navigationResponseReceived?.resolve();
if (this.#navigationResponseReceived) {
return;
}
this.#navigationResponseReceived = createDeferredPromise();
if (request.response() !== null) {
this.#navigationResponseReceived?.resolve();
}
}

#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 0049f27

Please sign in to comment.