diff --git a/packages/puppeteer-core/src/common/bidi/BrowsingContext.ts b/packages/puppeteer-core/src/common/bidi/BrowsingContext.ts index 9882f185..03171ee8 100644 --- a/packages/puppeteer-core/src/common/bidi/BrowsingContext.ts +++ b/packages/puppeteer-core/src/common/bidi/BrowsingContext.ts @@ -8,7 +8,6 @@ import type {CDPSession, Connection as CDPConnection} from '../Connection.js'; import {ProtocolError, TargetCloseError, TimeoutError} from '../Errors.js'; import {EventEmitter} from '../EventEmitter.js'; import {PuppeteerLifeCycleEvent} from '../LifecycleWatcher.js'; -import {TimeoutSettings} from '../TimeoutSettings.js'; import {getPageContent, setPageContent, waitWithTimeout} from '../util.js'; import {Connection} from './Connection.js'; @@ -111,19 +110,13 @@ export class CDPSessionWrapper extends EventEmitter implements CDPSession { * @internal */ export class BrowsingContext extends Realm { - #timeoutSettings: TimeoutSettings; #id: string; #url: string; #cdpSession: CDPSession; - constructor( - connection: Connection, - timeoutSettings: TimeoutSettings, - info: Bidi.BrowsingContext.Info - ) { + constructor(connection: Connection, info: Bidi.BrowsingContext.Info) { super(connection, info.context); this.connection = connection; - this.#timeoutSettings = timeoutSettings; this.#id = info.context; this.#url = info.url; this.#cdpSession = new CDPSessionWrapper(this); @@ -161,14 +154,11 @@ export class BrowsingContext extends Realm { options: { referer?: string; referrerPolicy?: string; - timeout?: number; + timeout: number; waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]; - } = {} + } ): Promise { - const { - waitUntil = 'load', - timeout = this.#timeoutSettings.navigationTimeout(), - } = options; + const {waitUntil = 'load', timeout} = options; const readinessState = lifeCycleToReadinessState.get( getWaitUntilSingle(waitUntil) @@ -197,11 +187,8 @@ export class BrowsingContext extends Realm { } } - async reload(options: WaitForOptions = {}): Promise { - const { - waitUntil = 'load', - timeout = this.#timeoutSettings.navigationTimeout(), - } = options; + async reload(options: WaitForOptions & {timeout: number}): Promise { + const {waitUntil = 'load', timeout} = options; const readinessState = lifeCycleToReadinessState.get( getWaitUntilSingle(waitUntil) @@ -220,14 +207,11 @@ export class BrowsingContext extends Realm { async setContent( html: string, options: { - timeout?: number; + timeout: number; waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]; } ): Promise { - const { - waitUntil = 'load', - timeout = this.#timeoutSettings.navigationTimeout(), - } = options; + const {waitUntil = 'load', timeout} = options; const waitUntilEvent = lifeCycleToSubscribedEvent.get( getWaitUntilSingle(waitUntil) diff --git a/packages/puppeteer-core/src/common/bidi/Frame.ts b/packages/puppeteer-core/src/common/bidi/Frame.ts index d5004c28..56db90c4 100644 --- a/packages/puppeteer-core/src/common/bidi/Frame.ts +++ b/packages/puppeteer-core/src/common/bidi/Frame.ts @@ -131,7 +131,10 @@ export class Frame extends BaseFrame { waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]; } ): Promise { - const navigationId = await this.#context.goto(url, options); + const navigationId = await this.#context.goto(url, { + ...options, + timeout: options?.timeout ?? this.#timeoutSettings.navigationTimeout(), + }); return this.#page.getNavigationResponse(navigationId); } @@ -142,7 +145,10 @@ export class Frame extends BaseFrame { waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]; } ): Promise { - return this.#context.setContent(html, options); + return this.#context.setContent(html, { + ...options, + timeout: options?.timeout ?? this.#timeoutSettings.navigationTimeout(), + }); } override content(): Promise { diff --git a/packages/puppeteer-core/src/common/bidi/Page.ts b/packages/puppeteer-core/src/common/bidi/Page.ts index 8ee38e59..6054d431 100644 --- a/packages/puppeteer-core/src/common/bidi/Page.ts +++ b/packages/puppeteer-core/src/common/bidi/Page.ts @@ -223,11 +223,7 @@ export class Page extends PageBase { !this.frame(info.context) && (this.frame(info.parent ?? '') || !this.#frameTree.getMainFrame()) ) { - const context = new BrowsingContext( - this.#connection, - this.#timeoutSettings, - info - ); + const context = new BrowsingContext(this.#connection, info); this.#connection.registerBrowsingContexts(context); const frame = new Frame( @@ -396,7 +392,13 @@ export class Page extends PageBase { response.url() === this.url() ); }), - this.mainFrame().context().reload(options), + this.mainFrame() + .context() + .reload({ + ...options, + timeout: + options?.timeout ?? this.#timeoutSettings.navigationTimeout(), + }), ]); return response;