Chrome DevTools for coding agents
test: Support configurable navigation timeout and increase it for Windows tests (#2482)
Natasha Gorshunovac6f6e88199cd
diff --git a/src/McpContext.ts b/src/McpContext.tsindex cdde1200..9fe06260 100644--- a/src/McpContext.ts+++ b/src/McpContext.ts@@ -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@@ -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();diff --git a/src/McpPage.ts b/src/McpPage.tsindex 60992190..7695ff6a 100644--- a/src/McpPage.ts+++ b/src/McpPage.ts@@ -137,6 +137,7 @@ export class McpPage implements ContextPage {#hasNetworkBlockOrAllowlist: boolean;#locatorClass: typeof Locator;+ #navigationTimeout: number;constructor(page: Page,@@ -145,10 +146,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;@@ -831,7 +834,7 @@ export class McpPage implements ContextPage {this.networkConditions,);this.pptrPage.setDefaultNavigationTimeout(- NAVIGATION_TIMEOUT * networkMultiplier * cpuMultiplier,+ this.#navigationTimeout * networkMultiplier * cpuMultiplier,);}diff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.tsindex ee010874..e4e097c8 100644--- a/tests/McpResponse.test.ts+++ b/tests/McpResponse.test.ts@@ -296,17 +296,24 @@ describe('McpResponse', () => {});it('adds throttling setting when it is not null', async t => {- await withMcpContext(async (response, context) => {- await context- .getSelectedMcpPage()- .emulate({networkConditions: 'Slow 3G'});- const {content, structuredContent} = await response.handle(context);- assert.equal(content[0].type, 'text');- t.assert.snapshot(getTextContent(content[0]));- t.assert.snapshot(- JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),- );- });+ await withMcpContext(+ async (response, context) => {+ await context+ .getSelectedMcpPage()+ .emulate({networkConditions: 'Slow 3G'});+ const {content, structuredContent} = await response.handle(context);+ assert.equal(content[0].type, 'text');+ t.assert.snapshot(getTextContent(content[0]));+ t.assert.snapshot(+ JSON.stringify(+ stabilizeStructuredContent(structuredContent),+ null,+ 2,+ ),+ );+ },+ {navigationTimeout: 10000},+ );});it('does not include throttling setting when it is null', async t => {diff --git a/tests/utils.ts b/tests/utils.tsindex 61b75992..dd3ae7ba 100644--- a/tests/utils.ts+++ b/tests/utils.ts@@ -164,6 +164,7 @@ export async function withMcpContext(blockedUrlPattern?: string[];allowedUrlPattern?: string[];allowUnrestrictedPaths?: boolean;+ navigationTimeout?: number;} = {},args: Partial<ParsedArguments> = {},) {@@ -183,6 +184,9 @@ export async function withMcpContext(allowList: options.allowedUrlPattern,blocklist: options.blockedUrlPattern,allowUnrestrictedPaths: options.allowUnrestrictedPaths ?? false,+ navigationTimeout:+ options.navigationTimeout ??+ (process.platform === 'win32' ? 20000 : undefined),},Locator,);