diff --git a/packages/puppeteer-core/src/common/HTTPRequest.ts b/packages/puppeteer-core/src/common/HTTPRequest.ts index 5150c7db3ea..7eeee5ee239 100644 --- a/packages/puppeteer-core/src/common/HTTPRequest.ts +++ b/packages/puppeteer-core/src/common/HTTPRequest.ts @@ -192,26 +192,6 @@ export class HTTPRequest extends BaseHTTPRequest { return this._redirectChain.slice(); } - /** - * Access information about the request's failure. - * - * @remarks - * - * @example - * - * Example of logging all failed requests: - * - * ```ts - * page.on('requestfailed', request => { - * console.log(request.url() + ' ' + request.failure().errorText); - * }); - * ``` - * - * @returns `null` unless the request failed. If the request fails this can - * return an object with `errorText` containing a human-readable error - * message, e.g. `net::ERR_FAILED`. It is not guaranteed that there will be - * failure text if the request fails. - */ override failure(): {errorText: string} | null { if (!this._failureText) { return null; @@ -221,35 +201,6 @@ export class HTTPRequest extends BaseHTTPRequest { }; } - /** - * Continues request with optional request overrides. - * - * @remarks - * - * To use this, request - * interception should be enabled with {@link Page.setRequestInterception}. - * - * Exception is immediately thrown if the request interception is not enabled. - * - * @example - * - * ```ts - * await page.setRequestInterception(true); - * page.on('request', request => { - * // Override headers - * const headers = Object.assign({}, request.headers(), { - * foo: 'bar', // set "foo" header - * origin: undefined, // remove "origin" header - * }); - * request.continue({headers}); - * }); - * ``` - * - * @param overrides - optional overrides to apply to the request. - * @param priority - If provided, intercept is resolved using - * cooperative handling rules. Otherwise, intercept is resolved - * immediately. - */ override async continue( overrides: ContinueRequestOverrides = {}, priority?: number diff --git a/packages/puppeteer-core/src/common/HTTPResponse.ts b/packages/puppeteer-core/src/common/HTTPResponse.ts index c6a2d723767..a43aa17195e 100644 --- a/packages/puppeteer-core/src/common/HTTPResponse.ts +++ b/packages/puppeteer-core/src/common/HTTPResponse.ts @@ -19,6 +19,7 @@ import { HTTPResponse as BaseHTTPResponse, RemoteAddress, } from '../api/HTTPResponse.js'; +import {createDeferredPromise} from '../util/DeferredPromise.js'; import {CDPSession} from './Connection.js'; import {ProtocolError} from './Errors.js'; @@ -33,8 +34,7 @@ export class HTTPResponse extends BaseHTTPResponse { #client: CDPSession; #request: HTTPRequest; #contentPromise: Promise | null = null; - #bodyLoadedPromise: Promise; - #bodyLoadedPromiseFulfill: (err: Error | void) => void = () => {}; + #bodyLoadedPromise = createDeferredPromise(); #remoteAddress: RemoteAddress; #status: number; #statusText: string; @@ -55,10 +55,6 @@ export class HTTPResponse extends BaseHTTPResponse { this.#client = client; this.#request = request; - this.#bodyLoadedPromise = new Promise(fulfill => { - this.#bodyLoadedPromiseFulfill = fulfill; - }); - this.#remoteAddress = { ip: responsePayload.remoteIPAddress, port: responsePayload.remotePort, @@ -105,9 +101,9 @@ export class HTTPResponse extends BaseHTTPResponse { override _resolveBody(err: Error | null): void { if (err) { - return this.#bodyLoadedPromiseFulfill(err); + return this.#bodyLoadedPromise.resolve(err); } - return this.#bodyLoadedPromiseFulfill(); + return this.#bodyLoadedPromise.resolve(); } override remoteAddress(): RemoteAddress { diff --git a/packages/puppeteer-core/src/common/LifecycleWatcher.ts b/packages/puppeteer-core/src/common/LifecycleWatcher.ts index a63c4407fbf..06899eb0e98 100644 --- a/packages/puppeteer-core/src/common/LifecycleWatcher.ts +++ b/packages/puppeteer-core/src/common/LifecycleWatcher.ts @@ -74,27 +74,10 @@ export class LifecycleWatcher { #eventListeners: PuppeteerEventListener[]; #initialLoaderId: string; - #sameDocumentNavigationCompleteCallback: (x?: Error) => void = noop; - #sameDocumentNavigationPromise = new Promise(fulfill => { - this.#sameDocumentNavigationCompleteCallback = fulfill; - }); - - #lifecycleCallback: () => void = noop; - #lifecyclePromise: Promise = new Promise(fulfill => { - this.#lifecycleCallback = fulfill; - }); - - #newDocumentNavigationCompleteCallback: (x?: Error) => void = noop; - #newDocumentNavigationPromise: Promise = new Promise( - fulfill => { - this.#newDocumentNavigationCompleteCallback = fulfill; - } - ); - - #terminationCallback: (x?: Error) => void = noop; - #terminationPromise: Promise = new Promise(fulfill => { - this.#terminationCallback = fulfill; - }); + #sameDocumentNavigationPromise = createDeferredPromise(); + #lifecyclePromise = createDeferredPromise(); + #newDocumentNavigationPromise = createDeferredPromise(); + #terminationPromise = createDeferredPromise(); #timeoutPromise: Promise; @@ -211,8 +194,7 @@ export class LifecycleWatcher { #onFrameDetached(frame: Frame): void { if (this.#frame === frame) { - this.#terminationCallback.call( - null, + this.#terminationPromise.resolve( new Error('Navigating frame was detached') ); return; @@ -227,7 +209,7 @@ export class LifecycleWatcher { } #terminate(error: Error): void { - this.#terminationCallback.call(null, error); + this.#terminationPromise.resolve(error); } sameDocumentNavigationPromise(): Promise { @@ -286,12 +268,12 @@ export class LifecycleWatcher { if (!checkLifecycle(this.#frame, this.#expectedLifecycle)) { return; } - this.#lifecycleCallback(); + this.#lifecyclePromise.resolve(); if (this.#hasSameDocumentNavigation) { - this.#sameDocumentNavigationCompleteCallback(); + this.#sameDocumentNavigationPromise.resolve(undefined); } if (this.#swapped || this.#frame._loaderId !== this.#initialLoaderId) { - this.#newDocumentNavigationCompleteCallback(); + this.#newDocumentNavigationPromise.resolve(undefined); } function checkLifecycle(