Chrome DevTools for coding agents
refactor: simplify the response texts (#1095)
Alex Rudenkocb0079efbbd4
diff --git a/src/McpResponse.ts b/src/McpResponse.tsindex e87ebac0..af4b1ee4 100644--- a/src/McpResponse.ts+++ b/src/McpResponse.ts@@ -503,7 +503,7 @@ export class McpResponse implements Response {extensionServiceWorkers?: object[];} = {};- const response = [`# ${toolName} response`];+ const response = [];if (this.#textResponseLines.length) {structuredContent.message = this.#textResponseLines.join('\n');response.push(...this.#textResponseLines);@@ -512,8 +512,7 @@ export class McpResponse implements Response {const networkConditions = this.#page?.networkConditions;if (networkConditions) {const timeout = this.#page!.pptrPage.getDefaultNavigationTimeout();- response.push(`## Network emulation`);- response.push(`Emulating: ${networkConditions}`);+ response.push(`Emulating network conditions: ${networkConditions}`);response.push(`Default navigation timeout set to ${timeout} ms`);structuredContent.networkConditions = networkConditions;structuredContent.navigationTimeout = timeout;@@ -521,29 +520,25 @@ export class McpResponse implements Response {const viewport = this.#page?.viewport;if (viewport) {- response.push(`## Viewport emulation`);response.push(`Emulating viewport: ${JSON.stringify(viewport)}`);structuredContent.viewport = viewport;}const userAgent = this.#page?.userAgent;if (userAgent) {- response.push(`## UserAgent emulation`);- response.push(`Emulating userAgent: ${userAgent}`);+ response.push(`Emulating user agent: ${userAgent}`);structuredContent.userAgent = userAgent;}const cpuThrottlingRate = this.#page?.cpuThrottlingRate ?? 1;if (cpuThrottlingRate > 1) {- response.push(`## CPU emulation`);- response.push(`Emulating: ${cpuThrottlingRate}x slowdown`);+ response.push(`Emulating CPU throttling: ${cpuThrottlingRate}x slowdown`);structuredContent.cpuThrottlingRate = cpuThrottlingRate;}const colorScheme = this.#page?.colorScheme;if (colorScheme) {- response.push(`## Color Scheme emulation`);- response.push(`Emulating: ${colorScheme}`);+ response.push(`Emulating color scheme: ${colorScheme}`);structuredContent.colorScheme = colorScheme;}diff --git a/tests/McpResponse.test.js.snapshot b/tests/McpResponse.test.js.snapshotindex 8356dbcd..85924457 100644--- a/tests/McpResponse.test.js.snapshot+++ b/tests/McpResponse.test.js.snapshot@@ -1,5 +1,4 @@exports[`McpResponse > add network request when attached 1`] = `-# test response## Request http://example.comStatus: pending### Request Headers@@ -42,7 +41,6 @@ exports[`McpResponse > add network request when attached 2`] = ``;exports[`McpResponse > add network request when attached with POST data 1`] = `-# test response## Request http://example.comStatus: 200### Request Headers@@ -96,7 +94,6 @@ exports[`McpResponse > add network request when attached with POST data 2`] = ``;exports[`McpResponse > add network requests when setting is true 1`] = `-# test response## Network requestsShowing 1-2 of 2 (Page 1 of 1).reqid=1 GET http://example.com [pending]@@ -134,7 +131,6 @@ exports[`McpResponse > add network requests when setting is true 2`] = ``;exports[`McpResponse > adds a message when no console messages exist 1`] = `-# test response## Console messages<no console messages found>`;@@ -144,7 +140,6 @@ exports[`McpResponse > adds a message when no console messages exist 2`] = ``;exports[`McpResponse > adds a prompt dialog 1`] = `-# test response# Open dialogprompt: message (default value: "default").Call handle_dialog to handle it before continuing.@@ -161,7 +156,6 @@ exports[`McpResponse > adds a prompt dialog 2`] = ``;exports[`McpResponse > adds an alert dialog 1`] = `-# test response# Open dialogalert: message.Call handle_dialog to handle it before continuing.@@ -178,9 +172,7 @@ exports[`McpResponse > adds an alert dialog 2`] = ``;exports[`McpResponse > adds color scheme emulation setting when it is set 1`] = `-# test response-## Color Scheme emulation-Emulating: dark+Emulating color scheme: dark`;exports[`McpResponse > adds color scheme emulation setting when it is set 2`] = `@@ -190,7 +182,6 @@ exports[`McpResponse > adds color scheme emulation setting when it is set 2`] =`;exports[`McpResponse > adds console messages when the setting is true 1`] = `-# test response## Console messagesShowing 1-1 of 1 (Page 1 of 1).msgid=1 [log] Hello from the test (1 args)@@ -219,9 +210,7 @@ exports[`McpResponse > adds console messages when the setting is true 2`] = ``;exports[`McpResponse > adds cpu throttling setting when it is over 1 1`] = `-# test response-## CPU emulation-Emulating: 4x slowdown+Emulating CPU throttling: 4x slowdown`;exports[`McpResponse > adds cpu throttling setting when it is over 1 2`] = `@@ -231,13 +220,15 @@ exports[`McpResponse > adds cpu throttling setting when it is over 1 2`] = ``;exports[`McpResponse > adds image when image is attached 1`] = `++`;++exports[`McpResponse > adds image when image is attached 2`] = `{}`;exports[`McpResponse > adds throttling setting when it is not null 1`] = `-# test response-## Network emulation-Emulating: Slow 3G+Emulating network conditions: Slow 3GDefault navigation timeout set to 100000 ms`;@@ -249,9 +240,7 @@ exports[`McpResponse > adds throttling setting when it is not null 2`] = ``;exports[`McpResponse > adds userAgent emulation setting when it is set 1`] = `-# test response-## UserAgent emulation-Emulating userAgent: MyUA+Emulating user agent: MyUA`;exports[`McpResponse > adds userAgent emulation setting when it is set 2`] = `@@ -261,8 +250,6 @@ exports[`McpResponse > adds userAgent emulation setting when it is set 2`] = ``;exports[`McpResponse > adds viewport emulation setting when it is set 1`] = `-# test response-## Viewport emulationEmulating viewport: {"deviceScaleFactor":1,"isMobile":false,"hasTouch":false,"isLandscape":false,"width":400,"height":400}`;@@ -280,7 +267,6 @@ exports[`McpResponse > adds viewport emulation setting when it is set 2`] = ``;exports[`McpResponse > allows response text lines to be added 1`] = `-# test responseTesting 1Testing 2`;@@ -292,18 +278,34 @@ exports[`McpResponse > allows response text lines to be added 2`] = ``;exports[`McpResponse > does not include anything in response if snapshot is null 1`] = `++`;++exports[`McpResponse > does not include anything in response if snapshot is null 2`] = `{}`;exports[`McpResponse > does not include cpu throttling setting when it is 1 1`] = `++`;++exports[`McpResponse > does not include cpu throttling setting when it is 1 2`] = `{}`;exports[`McpResponse > does not include network requests when setting is false 1`] = `++`;++exports[`McpResponse > does not include network requests when setting is false 2`] = `{}`;exports[`McpResponse > does not include throttling setting when it is null 1`] = `++`;++exports[`McpResponse > does not include throttling setting when it is null 2`] = `{}`;@@ -312,7 +314,6 @@ exports[`McpResponse > doesn't list the issue message if mapping returns null 1``;exports[`McpResponse > list pages 1`] = `-# test response## Pages1: about:blank [selected]`;@@ -330,7 +331,6 @@ exports[`McpResponse > list pages 2`] = ``;exports[`McpResponse > returns correctly formatted snapshot for a simple tree 1`] = `-# test response## Latest page snapshotuid=1_0 RootWebArea "My test page" url="about:blank"uid=1_1 button "Click me" focusable focused@@ -364,7 +364,6 @@ exports[`McpResponse > returns correctly formatted snapshot for a simple tree 2``;exports[`McpResponse > returns values for textboxes 1`] = `-# test response## Latest page snapshotuid=1_0 RootWebArea "My test page" url="about:blank"uid=1_1 StaticText "username"@@ -399,7 +398,6 @@ exports[`McpResponse > returns values for textboxes 2`] = ``;exports[`McpResponse > returns verbose snapshot and structured content 1`] = `-# test response## Latest page snapshotuid=1_0 RootWebArea "My test page" url="about:blank"uid=1_1 ignored@@ -454,7 +452,6 @@ exports[`McpResponse > returns verbose snapshot and structured content 2`] = ``;exports[`McpResponse > saves snapshot to file and returns structured content 1`] = `-# test responseSaved snapshot to <file>`;@@ -728,7 +725,6 @@ exports[`McpResponse network pagination > returns subsequent page when pageIdx p`;exports[`McpResponse network pagination > trace insights > includes error if insight not found 1`] = `-# test responseNo Performance Insights for the given insight set id. Only use ids given in the "Available insight sets" list.`;@@ -737,7 +733,6 @@ exports[`McpResponse network pagination > trace insights > includes error if ins`;exports[`McpResponse network pagination > trace insights > includes the trace insight output 1`] = `-# test response## Insight Title: LCP breakdown## Insight Summary:@@ -787,7 +782,6 @@ exports[`McpResponse network pagination > trace insights > includes the trace in`;exports[`McpResponse network pagination > trace summaries > includes the trace summary text and structured data 1`] = `-# test response## Summary of Performance trace findings:URL: https://web.dev/Trace bounds: {min: 122410994891, max: 122416385853}@@ -982,7 +976,6 @@ exports[`McpResponse network pagination > trace summaries > includes the trace s`;exports[`McpResponse network request filtering > filters network requests by resource type 1`] = `-# test response## Network requestsShowing 1-2 of 2 (Page 1 of 1).reqid=1 GET http://example.com [pending]@@ -1020,7 +1013,6 @@ exports[`McpResponse network request filtering > filters network requests by res`;exports[`McpResponse network request filtering > filters network requests by single resource type 1`] = `-# test response## Network requestsShowing 1-1 of 1 (Page 1 of 1).reqid=1 GET http://example.com [pending]@@ -1050,7 +1042,6 @@ exports[`McpResponse network request filtering > filters network requests by sin`;exports[`McpResponse network request filtering > shows all requests when empty resourceTypes array is provided 1`] = `-# test response## Network requestsShowing 1-5 of 5 (Page 1 of 1).reqid=1 GET http://example.com [pending]@@ -1112,7 +1103,6 @@ exports[`McpResponse network request filtering > shows all requests when empty r`;exports[`McpResponse network request filtering > shows all requests when no filters are provided 1`] = `-# test response## Network requestsShowing 1-5 of 5 (Page 1 of 1).reqid=1 GET http://example.com [pending]@@ -1174,7 +1164,7 @@ exports[`McpResponse network request filtering > shows all requests when no filt`;exports[`McpResponse network request filtering > shows no requests when filter matches nothing 1`] = `-# test response+`;exports[`McpResponse network request filtering > shows no requests when filter matches nothing 2`] = `@@ -1182,7 +1172,6 @@ exports[`McpResponse network request filtering > shows no requests when filter m`;exports[`extensions > lists extensions 1`] = `-# test response## Extensionsid=id1 "Extension 1" v1.0 Enabledid=id2 "Extension 2" v2.0 Disabled@@ -1210,7 +1199,6 @@ exports[`extensions > lists extensions 2`] = ``;exports[`lighthouse > includes lighthouse report paths 1`] = `-# test response## Lighthouse Audit ResultsMode: navigationDevice: desktopdiff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.tsindex 0936a1e2..e2db88c5 100644--- a/tests/McpResponse.test.ts+++ b/tests/McpResponse.test.ts@@ -70,8 +70,7 @@ describe('McpResponse', () => {'test',context,);- assert.equal(content[0].type, 'text');- assert.deepStrictEqual(getTextContent(content[0]), `# test response`);+ t.assert.snapshot?.(getTextContent(content[0]));t.assert.snapshot?.(JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),);@@ -94,7 +93,6 @@ describe('McpResponse', () => {'test',context,);- assert.equal(content[0].type, 'text');t.assert.snapshot?.(getTextContent(content[0]));t.assert.snapshot?.(JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),@@ -303,8 +301,7 @@ describe('McpResponse', () => {context,);await context.emulate({});- assert.equal(content[0].type, 'text');- assert.strictEqual(getTextContent(content[0]), `# test response`);+ t.assert.snapshot?.(getTextContent(content[0]));t.assert.snapshot?.(JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),);@@ -317,7 +314,7 @@ describe('McpResponse', () => {'test',context,);- assert.strictEqual(getTextContent(content[0]), `# test response`);+ t.assert.snapshot?.(getTextContent(content[0]));assert.equal(content[1].type, 'image');assert.strictEqual(getImageContent(content[1]).data, 'imageBase64');assert.strictEqual(getImageContent(content[1]).mimeType, 'image/png');@@ -348,7 +345,7 @@ describe('McpResponse', () => {'test',context,);- assert.strictEqual(getTextContent(content[0]), `# test response`);+ t.assert.snapshot?.(getTextContent(content[0]));t.assert.snapshot?.(JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),);@@ -474,7 +471,7 @@ describe('McpResponse', () => {'test',context,);- assert.strictEqual(getTextContent(content[0]), `# test response`);+ t.assert.snapshot?.(getTextContent(content[0]));t.assert.snapshot?.(JSON.stringify(stabilizeStructuredContent(structuredContent), null, 2),);diff --git a/tests/index.test.js.snapshot b/tests/index.test.js.snapshotnew file mode 100644index 00000000..06a918df--- /dev/null+++ b/tests/index.test.js.snapshot@@ -0,0 +1,7 @@+exports[`e2e > calls a tool 1`] = `+[{"type":"text","text":"## Pages\\n1: about:blank [selected]"}]+`;++exports[`e2e > calls a tool multiple times 1`] = `+[{"type":"text","text":"## Pages\\n1: about:blank [selected]"}]+`;diff --git a/tests/index.test.ts b/tests/index.test.tsindex ed1d7595..8bf8528d 100644--- a/tests/index.test.ts+++ b/tests/index.test.ts@@ -47,24 +47,17 @@ describe('e2e', () => {await client.close();}}- it('calls a tool', async () => {+ it('calls a tool', async t => {await withClient(async client => {const result = await client.callTool({name: 'list_pages',arguments: {},});- assert.deepStrictEqual(result, {- content: [- {- type: 'text',- text: '# list_pages response\n## Pages\n1: about:blank [selected]',- },- ],- });+ t.assert.snapshot?.(JSON.stringify(result.content));});});- it('calls a tool multiple times', async () => {+ it('calls a tool multiple times', async t => {await withClient(async client => {let result = await client.callTool({name: 'list_pages',@@ -74,14 +67,7 @@ describe('e2e', () => {name: 'list_pages',arguments: {},});- assert.deepStrictEqual(result, {- content: [- {- type: 'text',- text: '# list_pages response\n## Pages\n1: about:blank [selected]',- },- ],- });+ t.assert.snapshot?.(JSON.stringify(result.content));});});diff --git a/tests/tools/console.test.js.snapshot b/tests/tools/console.test.js.snapshotindex 5ded1f08..fb8e36f5 100644--- a/tests/tools/console.test.js.snapshot+++ b/tests/tools/console.test.js.snapshot@@ -1,5 +1,4 @@exports[`console > get_console_message > applies source maps to stack traces of Error object (with cause) console.log arguments 1`] = `-# test responseID: 1Message: log> foo failed Error: bar failed### Arguments@@ -21,7 +20,6 @@ Note: line and column numbers use 1-based indexing`;exports[`console > get_console_message > applies source maps to stack traces of Error object console.log arguments 1`] = `-# test responseID: 1Message: log> An error happened: Error: b00m!### Arguments@@ -39,7 +37,6 @@ Note: line and column numbers use 1-based indexing`;exports[`console > get_console_message > applies source maps to stack traces of console messages 1`] = `-# test responseID: 1Message: warn> hello world### Arguments@@ -53,7 +50,6 @@ Note: line and column numbers use 1-based indexing`;exports[`console > get_console_message > applies source maps to stack traces of uncaught exceptions 1`] = `-# test responseID: 1Message: error> Uncaught Error: b00m!### Stack trace@@ -65,7 +61,6 @@ Note: line and column numbers use 1-based indexing`;exports[`console > get_console_message > applies source maps to stack traces of uncaught exceptions with cause 1`] = `-# test responseID: 1Message: error> Uncaught Error: foo failed### Stack trace@@ -84,7 +79,6 @@ Note: line and column numbers use 1-based indexing`;exports[`console > get_console_message > ignores frames from ignore listed URLs 1`] = `-# test responseID: 1Message: log> hello from callback### Arguments@@ -97,7 +91,6 @@ Note: line and column numbers use 1-based indexing`;exports[`console > get_console_message > issues type > gets issue details with node id parsing 1`] = `-# test responseID: 1Message: issue> An element doesn't have an autocomplete attribute@@ -111,7 +104,6 @@ uid=1_1 data={"violatingNodeAttribute":"name"}`;exports[`console > get_console_message > issues type > gets issue details with request id parsing 1`] = `-# test responseID: <ID>Message: issue> Ensure CORS response header values are valid@@ -127,7 +119,6 @@ reqid=<reqid> data={"corsErrorStatus":{"corsError":"PreflightMissingAllowOriginH`;exports[`console > list_console_messages > lists error objects 1`] = `-# test response## Console messagesShowing 1-1 of 1 (Page 1 of 1).msgid=1 [error] Error: This is an error (1 args)diff --git a/tests/tools/network.test.js.snapshot b/tests/tools/network.test.js.snapshotindex 4b047298..243640a8 100644--- a/tests/tools/network.test.js.snapshot+++ b/tests/tools/network.test.js.snapshot@@ -1,5 +1,4 @@exports[`network > network_get_request > should get request from previous navigations 1`] = `-# get_request response## Request http://localhost:<port>/oneStatus: 200### Request Headers@@ -28,14 +27,12 @@ Status: 200`;exports[`network > network_list_requests > list requests form current navigations only 1`] = `-# list_request response## Network requestsShowing 1-1 of 1 (Page 1 of 1).reqid=3 GET http://localhost:<port>/three [200]`;exports[`network > network_list_requests > list requests from previous navigations 1`] = `-# list_request response## Network requestsShowing 1-3 of 3 (Page 1 of 1).reqid=1 GET http://localhost:<port>/one [200]@@ -44,7 +41,6 @@ reqid=3 GET http://localhost:<port>/three [200]`;exports[`network > network_list_requests > list requests from previous navigations from redirects 1`] = `-# list_request response## Network requestsShowing 1-3 of 3 (Page 1 of 1).reqid=1 GET http://localhost:<port>/redirect [302]