Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/McpContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ interface McpContextOptions {
// Whether this context replaces a previous one after a browser reconnect.
// Surfaces a one-time note in the next response.
reconnected?: boolean;
// Custom navigation timeout in milliseconds to override default.
navigationTimeout?: number;
}

// Page ids are handed out from a process-wide counter so they stay unique
Expand Down Expand Up @@ -503,6 +505,7 @@ export class McpContext implements Context {
isolatedContextName: this.#getBrowserContextToNameMap().get(
page.browserContext(),
),
navigationTimeout: this.#options.navigationTimeout,
});
this.#mcpPages.set(page, mcpPage);
await mcpPage.init();
Expand Down
14 changes: 12 additions & 2 deletions src/McpPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class McpPage implements ContextPage {

#hasNetworkBlockOrAllowlist: boolean;
#locatorClass: typeof Locator;
#navigationTimeout: number;

constructor(
page: Page,
Expand All @@ -147,10 +148,12 @@ export class McpPage implements ContextPage {
hasNetworkBlockOrAllowlist: boolean;
locatorClass: typeof Locator;
isolatedContextName?: string;
navigationTimeout?: number;
},
) {
this.#hasNetworkBlockOrAllowlist = options.hasNetworkBlockOrAllowlist;
this.#locatorClass = options.locatorClass;
this.#navigationTimeout = options.navigationTimeout ?? NAVIGATION_TIMEOUT;
this.pptrPage = page;
this.id = id;
this.isolatedContextName = options.isolatedContextName;
Expand Down Expand Up @@ -409,7 +412,14 @@ export class McpPage implements ContextPage {
cpuMultiplier: number,
networkMultiplier: number,
): WaitForHelper {
return new WaitForHelper(this.pptrPage, cpuMultiplier, networkMultiplier);
const navigationTimeout =
this.#navigationTimeout * networkMultiplier * cpuMultiplier;
return new WaitForHelper(
this.pptrPage,
cpuMultiplier,
networkMultiplier,
navigationTimeout,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

navigation timeout in the WaitForHelper is a different timeout IIUC. I think we should not pass this.#navigationTimeout * networkMultiplier * cpuMultiplier as navigation timeout for WaitForHelper here. Additionally, I do not think the WaitForHelper timeout was the cause of flakiness.

);
}

waitForEventsAfterAction(
Expand Down Expand Up @@ -827,7 +837,7 @@ export class McpPage implements ContextPage {
this.networkConditions,
);
this.pptrPage.setDefaultNavigationTimeout(
NAVIGATION_TIMEOUT * networkMultiplier * cpuMultiplier,
this.#navigationTimeout * networkMultiplier * cpuMultiplier,
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/WaitForHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export class WaitForHelper {
page: Page,
cpuTimeoutMultiplier: number,
networkTimeoutMultiplier: number,
navigationTimeout?: number,
) {
this.#stableDomTimeout = 3000 * cpuTimeoutMultiplier;
this.#stableDomFor = 100 * cpuTimeoutMultiplier;
this.#expectNavigationIn = 100 * cpuTimeoutMultiplier;
this.#navigationTimeout = 3000 * networkTimeoutMultiplier;
this.#navigationTimeout =
navigationTimeout ?? 3000 * networkTimeoutMultiplier;
this.#page = page as unknown as CdpPage;
this.#initialUrl = page.url();
}
Expand Down
1 change: 1 addition & 0 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export async function withMcpContext(
allowList: options.allowedUrlPattern,
blocklist: options.blockedUrlPattern,
allowUnrestrictedPaths: options.allowUnrestrictedPaths ?? false,
navigationTimeout: process.platform === 'win32' ? 20000 : undefined
},
Locator,
);
Expand Down
Loading