chrome-devtools-mcp 0.8.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -9
- package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Console.js +1 -8
- package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Gzip.js +8 -6
- package/build/node_modules/chrome-devtools-frontend/front_end/core/common/ParsedURL.js +10 -20
- package/build/node_modules/chrome-devtools-frontend/front_end/core/common/SegmentedRange.js +1 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Settings.js +4 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/core/common/StringOutputStream.js +1 -4
- package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Worker.js +10 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/core/host/AidaClient.js +19 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/host/DispatchHttpRequestClient.js +54 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/host/GdpClient.js +6 -51
- package/build/node_modules/chrome-devtools-frontend/front_end/core/host/InspectorFrontendHost.js +2 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/core/host/InspectorFrontendHostAPI.js +32 -29
- package/build/node_modules/chrome-devtools-frontend/front_end/core/host/UserMetrics.js +15 -6
- package/build/node_modules/chrome-devtools-frontend/front_end/core/host/host.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/ArrayUtilities.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/core/protocol_client/CDPConnection.js +17 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/protocol_client/ConnectionTransport.js +12 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/protocol_client/InspectorBackend.js +81 -213
- package/build/node_modules/chrome-devtools-frontend/front_end/core/protocol_client/protocol_client.js +3 -8
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/AnimationModel.js +1 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSMatchedStyles.js +45 -10
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSModel.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSProperty.js +3 -6
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSPropertyParserMatchers.js +14 -10
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSRule.js +34 -6
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSStyleDeclaration.js +4 -4
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ChildTargetManager.js +8 -33
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/Connections.js +10 -47
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/DOMModel.js +4 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/DebuggerModel.js +3 -3
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/EnhancedTracesParser.js +17 -3
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js +371 -53
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkRequest.js +5 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/PreloadingModel.js +56 -13
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/RehydratingConnection.js +133 -10
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ResourceTreeModel.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/{models/source_map_scopes → core/sdk}/ScopeTreeCache.js +9 -5
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMap.js +50 -14
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMapManager.js +8 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMapScopesInfo.js +131 -8
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/TargetManager.js +0 -21
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/TraceObject.js +9 -6
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/sdk-meta.js +8 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/sdk.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/generated/ARIAProperties.js +1301 -174
- package/build/node_modules/chrome-devtools-frontend/front_end/generated/Deprecation.js +7 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/generated/InspectorBackendCommands.js +9 -45
- package/build/node_modules/chrome-devtools-frontend/front_end/generated/SupportedCSSProperties.js +74 -19
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceInsightFormatter.js +50 -34
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.js +46 -45
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AICallTree.js +2 -3
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AIContext.js +10 -25
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/CompilerScriptMapping.js +45 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/DebuggerWorkspaceBinding.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/cpu_profile/ProfileTreeModel.js +6 -7
- package/build/node_modules/chrome-devtools-frontend/front_end/models/formatter/FormatterWorkerPool.js +14 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/NamesResolver.js +5 -11
- package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/source_map_scopes.js +1 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/StackTraceModel.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/stack_trace/Trie.js +8 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/ModelImpl.js +6 -3
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/extras/TraceTree.js +10 -3
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/MetaHandler.js +4 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/NetworkRequestsHandler.js +12 -3
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/UserTimingsHandler.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/CLSCulprits.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/Cache.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/DOMSize.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/DocumentLatency.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/DuplicatedJavaScript.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/FontDisplay.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/ForcedReflow.js +3 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/INPBreakdown.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/ImageDelivery.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/LCPBreakdown.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/LCPDiscovery.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/LegacyJavaScript.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/ModernHTTP.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/NetworkDependencyTree.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/RenderBlocking.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/SlowCSSSelector.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/ThirdParties.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/Viewport.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/types/TraceEvents.js +3 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace_source_maps_resolver/SourceMapsResolver.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/mcp/mcp.js +14 -0
- package/build/src/DevToolsConnectionAdapter.js +33 -0
- package/build/src/DevtoolsUtils.js +44 -0
- package/build/src/McpContext.js +182 -33
- package/build/src/McpResponse.js +169 -57
- package/build/src/PageCollector.js +123 -27
- package/build/src/WaitForHelper.js +5 -0
- package/build/src/browser.js +24 -12
- package/build/src/cli.js +87 -6
- package/build/src/formatters/consoleFormatter.js +29 -62
- package/build/src/formatters/networkFormatter.js +5 -6
- package/build/src/formatters/snapshotFormatter.js +28 -11
- package/build/src/logger.js +1 -1
- package/build/src/main.js +24 -6
- package/build/src/polyfill.js +2 -2
- package/build/src/third_party/THIRD_PARTY_NOTICES +1413 -0
- package/build/src/third_party/index.js +82791 -0
- package/build/src/tools/ToolDefinition.js +2 -2
- package/build/src/tools/categories.js +17 -9
- package/build/src/tools/console.js +71 -6
- package/build/src/tools/emulation.js +40 -48
- package/build/src/tools/input.js +57 -27
- package/build/src/tools/network.js +43 -13
- package/build/src/tools/pages.js +75 -49
- package/build/src/tools/performance.js +13 -10
- package/build/src/tools/screenshot.js +10 -9
- package/build/src/tools/script.js +29 -15
- package/build/src/tools/snapshot.js +27 -23
- package/build/src/trace-processing/parse.js +6 -16
- package/build/src/utils/keyboard.js +291 -0
- package/build/src/utils/types.js +6 -0
- package/package.json +16 -12
package/build/src/tools/pages.js
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import z from 'zod';
|
|
7
6
|
import { logger } from '../logger.js';
|
|
8
|
-
import {
|
|
7
|
+
import { zod } from '../third_party/index.js';
|
|
8
|
+
import { ToolCategory } from './categories.js';
|
|
9
9
|
import { CLOSE_PAGE_ERROR, defineTool, timeoutSchema } from './ToolDefinition.js';
|
|
10
10
|
export const listPages = defineTool({
|
|
11
11
|
name: 'list_pages',
|
|
12
12
|
description: `Get a list of pages open in the browser.`,
|
|
13
13
|
annotations: {
|
|
14
|
-
category:
|
|
14
|
+
category: ToolCategory.NAVIGATION,
|
|
15
15
|
readOnlyHint: true,
|
|
16
16
|
},
|
|
17
17
|
schema: {},
|
|
@@ -23,11 +23,11 @@ export const selectPage = defineTool({
|
|
|
23
23
|
name: 'select_page',
|
|
24
24
|
description: `Select a page as a context for future tool calls.`,
|
|
25
25
|
annotations: {
|
|
26
|
-
category:
|
|
26
|
+
category: ToolCategory.NAVIGATION,
|
|
27
27
|
readOnlyHint: true,
|
|
28
28
|
},
|
|
29
29
|
schema: {
|
|
30
|
-
pageIdx:
|
|
30
|
+
pageIdx: zod
|
|
31
31
|
.number()
|
|
32
32
|
.describe('The index of the page to select. Call list_pages to list pages.'),
|
|
33
33
|
},
|
|
@@ -42,11 +42,11 @@ export const closePage = defineTool({
|
|
|
42
42
|
name: 'close_page',
|
|
43
43
|
description: `Closes the page by its index. The last open page cannot be closed.`,
|
|
44
44
|
annotations: {
|
|
45
|
-
category:
|
|
45
|
+
category: ToolCategory.NAVIGATION,
|
|
46
46
|
readOnlyHint: false,
|
|
47
47
|
},
|
|
48
48
|
schema: {
|
|
49
|
-
pageIdx:
|
|
49
|
+
pageIdx: zod
|
|
50
50
|
.number()
|
|
51
51
|
.describe('The index of the page to close. Call list_pages to list pages.'),
|
|
52
52
|
},
|
|
@@ -69,11 +69,11 @@ export const newPage = defineTool({
|
|
|
69
69
|
name: 'new_page',
|
|
70
70
|
description: `Creates a new page`,
|
|
71
71
|
annotations: {
|
|
72
|
-
category:
|
|
72
|
+
category: ToolCategory.NAVIGATION,
|
|
73
73
|
readOnlyHint: false,
|
|
74
74
|
},
|
|
75
75
|
schema: {
|
|
76
|
-
url:
|
|
76
|
+
url: zod.string().describe('URL to load in a new page.'),
|
|
77
77
|
...timeoutSchema,
|
|
78
78
|
},
|
|
79
79
|
handler: async (request, response, context) => {
|
|
@@ -90,34 +90,19 @@ export const navigatePage = defineTool({
|
|
|
90
90
|
name: 'navigate_page',
|
|
91
91
|
description: `Navigates the currently selected page to a URL.`,
|
|
92
92
|
annotations: {
|
|
93
|
-
category:
|
|
93
|
+
category: ToolCategory.NAVIGATION,
|
|
94
94
|
readOnlyHint: false,
|
|
95
95
|
},
|
|
96
96
|
schema: {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
response.setIncludePages(true);
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
export const navigatePageHistory = defineTool({
|
|
111
|
-
name: 'navigate_page_history',
|
|
112
|
-
description: `Navigates the currently selected page.`,
|
|
113
|
-
annotations: {
|
|
114
|
-
category: ToolCategories.NAVIGATION_AUTOMATION,
|
|
115
|
-
readOnlyHint: false,
|
|
116
|
-
},
|
|
117
|
-
schema: {
|
|
118
|
-
navigate: z
|
|
119
|
-
.enum(['back', 'forward'])
|
|
120
|
-
.describe('Whether to navigate back or navigate forward in the selected pages history'),
|
|
97
|
+
type: zod
|
|
98
|
+
.enum(['url', 'back', 'forward', 'reload'])
|
|
99
|
+
.optional()
|
|
100
|
+
.describe('Navigate the page by URL, back or forward in history, or reload.'),
|
|
101
|
+
url: zod.string().optional().describe('Target URL (only type=url)'),
|
|
102
|
+
ignoreCache: zod
|
|
103
|
+
.boolean()
|
|
104
|
+
.optional()
|
|
105
|
+
.describe('Whether to ignore cache on reload.'),
|
|
121
106
|
...timeoutSchema,
|
|
122
107
|
},
|
|
123
108
|
handler: async (request, response, context) => {
|
|
@@ -125,17 +110,58 @@ export const navigatePageHistory = defineTool({
|
|
|
125
110
|
const options = {
|
|
126
111
|
timeout: request.params.timeout,
|
|
127
112
|
};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
await page.goBack(options);
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
await page.goForward(options);
|
|
134
|
-
}
|
|
113
|
+
if (!request.params.type && !request.params.url) {
|
|
114
|
+
throw new Error('Either URL or a type is required.');
|
|
135
115
|
}
|
|
136
|
-
|
|
137
|
-
|
|
116
|
+
if (!request.params.type) {
|
|
117
|
+
request.params.type = 'url';
|
|
138
118
|
}
|
|
119
|
+
await context.waitForEventsAfterAction(async () => {
|
|
120
|
+
switch (request.params.type) {
|
|
121
|
+
case 'url':
|
|
122
|
+
if (!request.params.url) {
|
|
123
|
+
throw new Error('A URL is required for navigation of type=url.');
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
await page.goto(request.params.url, options);
|
|
127
|
+
response.appendResponseLine(`Successfully navigated to ${request.params.url}.`);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
response.appendResponseLine(`Unable to navigate in the selected page: ${error.message}.`);
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
case 'back':
|
|
134
|
+
try {
|
|
135
|
+
await page.goBack(options);
|
|
136
|
+
response.appendResponseLine(`Successfully navigated back to ${page.url()}.`);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
response.appendResponseLine(`Unable to navigate back in the selected page: ${error.message}.`);
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
case 'forward':
|
|
143
|
+
try {
|
|
144
|
+
await page.goForward(options);
|
|
145
|
+
response.appendResponseLine(`Successfully navigated forward to ${page.url()}.`);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
response.appendResponseLine(`Unable to navigate forward in the selected page: ${error.message}.`);
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
case 'reload':
|
|
152
|
+
try {
|
|
153
|
+
await page.reload({
|
|
154
|
+
...options,
|
|
155
|
+
ignoreCache: request.params.ignoreCache,
|
|
156
|
+
});
|
|
157
|
+
response.appendResponseLine(`Successfully reloaded the page.`);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
response.appendResponseLine(`Unable to reload the selected page: ${error.message}.`);
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
139
165
|
response.setIncludePages(true);
|
|
140
166
|
},
|
|
141
167
|
});
|
|
@@ -143,12 +169,12 @@ export const resizePage = defineTool({
|
|
|
143
169
|
name: 'resize_page',
|
|
144
170
|
description: `Resizes the selected page's window so that the page has specified dimension`,
|
|
145
171
|
annotations: {
|
|
146
|
-
category:
|
|
172
|
+
category: ToolCategory.EMULATION,
|
|
147
173
|
readOnlyHint: false,
|
|
148
174
|
},
|
|
149
175
|
schema: {
|
|
150
|
-
width:
|
|
151
|
-
height:
|
|
176
|
+
width: zod.number().describe('Page width'),
|
|
177
|
+
height: zod.number().describe('Page height'),
|
|
152
178
|
},
|
|
153
179
|
handler: async (request, response, context) => {
|
|
154
180
|
const page = context.getSelectedPage();
|
|
@@ -164,14 +190,14 @@ export const handleDialog = defineTool({
|
|
|
164
190
|
name: 'handle_dialog',
|
|
165
191
|
description: `If a browser dialog was opened, use this command to handle it`,
|
|
166
192
|
annotations: {
|
|
167
|
-
category:
|
|
193
|
+
category: ToolCategory.INPUT,
|
|
168
194
|
readOnlyHint: false,
|
|
169
195
|
},
|
|
170
196
|
schema: {
|
|
171
|
-
action:
|
|
197
|
+
action: zod
|
|
172
198
|
.enum(['accept', 'dismiss'])
|
|
173
199
|
.describe('Whether to dismiss or accept the dialog'),
|
|
174
|
-
promptText:
|
|
200
|
+
promptText: zod
|
|
175
201
|
.string()
|
|
176
202
|
.optional()
|
|
177
203
|
.describe('Optional prompt text to enter into the dialog.'),
|
|
@@ -3,23 +3,23 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import z from 'zod';
|
|
7
6
|
import { logger } from '../logger.js';
|
|
7
|
+
import { zod } from '../third_party/index.js';
|
|
8
8
|
import { getInsightOutput, getTraceSummary, parseRawTraceBuffer, traceResultIsSuccess, } from '../trace-processing/parse.js';
|
|
9
|
-
import {
|
|
9
|
+
import { ToolCategory } from './categories.js';
|
|
10
10
|
import { defineTool } from './ToolDefinition.js';
|
|
11
11
|
export const startTrace = defineTool({
|
|
12
12
|
name: 'performance_start_trace',
|
|
13
13
|
description: 'Starts a performance trace recording on the selected page. This can be used to look for performance problems and insights to improve the performance of the page. It will also report Core Web Vital (CWV) scores for the page.',
|
|
14
14
|
annotations: {
|
|
15
|
-
category:
|
|
15
|
+
category: ToolCategory.PERFORMANCE,
|
|
16
16
|
readOnlyHint: true,
|
|
17
17
|
},
|
|
18
18
|
schema: {
|
|
19
|
-
reload:
|
|
19
|
+
reload: zod
|
|
20
20
|
.boolean()
|
|
21
21
|
.describe('Determines if, once tracing has started, the page should be automatically reloaded.'),
|
|
22
|
-
autoStop:
|
|
22
|
+
autoStop: zod
|
|
23
23
|
.boolean()
|
|
24
24
|
.describe('Determines if the trace recording should be automatically stopped.'),
|
|
25
25
|
},
|
|
@@ -79,7 +79,7 @@ export const stopTrace = defineTool({
|
|
|
79
79
|
name: 'performance_stop_trace',
|
|
80
80
|
description: 'Stops the active performance trace recording on the selected page.',
|
|
81
81
|
annotations: {
|
|
82
|
-
category:
|
|
82
|
+
category: ToolCategory.PERFORMANCE,
|
|
83
83
|
readOnlyHint: true,
|
|
84
84
|
},
|
|
85
85
|
schema: {},
|
|
@@ -93,13 +93,16 @@ export const stopTrace = defineTool({
|
|
|
93
93
|
});
|
|
94
94
|
export const analyzeInsight = defineTool({
|
|
95
95
|
name: 'performance_analyze_insight',
|
|
96
|
-
description: 'Provides more detailed information on a specific Performance Insight that was highlighted in the results of a trace recording.',
|
|
96
|
+
description: 'Provides more detailed information on a specific Performance Insight of an insight set that was highlighted in the results of a trace recording.',
|
|
97
97
|
annotations: {
|
|
98
|
-
category:
|
|
98
|
+
category: ToolCategory.PERFORMANCE,
|
|
99
99
|
readOnlyHint: true,
|
|
100
100
|
},
|
|
101
101
|
schema: {
|
|
102
|
-
|
|
102
|
+
insightSetId: zod
|
|
103
|
+
.string()
|
|
104
|
+
.describe('The id for the specific insight set. Only use the ids given in the "Available insight sets" list.'),
|
|
105
|
+
insightName: zod
|
|
103
106
|
.string()
|
|
104
107
|
.describe('The name of the Insight you want more information on. For example: "DocumentLatency" or "LCPBreakdown"'),
|
|
105
108
|
},
|
|
@@ -109,7 +112,7 @@ export const analyzeInsight = defineTool({
|
|
|
109
112
|
response.appendResponseLine('No recorded traces found. Record a performance trace so you have Insights to analyze.');
|
|
110
113
|
return;
|
|
111
114
|
}
|
|
112
|
-
const insightOutput = getInsightOutput(lastRecording, request.params.insightName);
|
|
115
|
+
const insightOutput = getInsightOutput(lastRecording, request.params.insightSetId, request.params.insightName);
|
|
113
116
|
if ('error' in insightOutput) {
|
|
114
117
|
response.appendResponseLine(insightOutput.error);
|
|
115
118
|
return;
|
|
@@ -3,36 +3,37 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
6
|
+
import { zod } from '../third_party/index.js';
|
|
7
|
+
import { ToolCategory } from './categories.js';
|
|
8
8
|
import { defineTool } from './ToolDefinition.js';
|
|
9
9
|
export const screenshot = defineTool({
|
|
10
10
|
name: 'take_screenshot',
|
|
11
11
|
description: `Take a screenshot of the page or element.`,
|
|
12
12
|
annotations: {
|
|
13
|
-
category:
|
|
14
|
-
|
|
13
|
+
category: ToolCategory.DEBUGGING,
|
|
14
|
+
// Not read-only due to filePath param.
|
|
15
|
+
readOnlyHint: false,
|
|
15
16
|
},
|
|
16
17
|
schema: {
|
|
17
|
-
format:
|
|
18
|
+
format: zod
|
|
18
19
|
.enum(['png', 'jpeg', 'webp'])
|
|
19
20
|
.default('png')
|
|
20
21
|
.describe('Type of format to save the screenshot as. Default is "png"'),
|
|
21
|
-
quality:
|
|
22
|
+
quality: zod
|
|
22
23
|
.number()
|
|
23
24
|
.min(0)
|
|
24
25
|
.max(100)
|
|
25
26
|
.optional()
|
|
26
27
|
.describe('Compression quality for JPEG and WebP formats (0-100). Higher values mean better quality but larger file sizes. Ignored for PNG format.'),
|
|
27
|
-
uid:
|
|
28
|
+
uid: zod
|
|
28
29
|
.string()
|
|
29
30
|
.optional()
|
|
30
31
|
.describe('The uid of an element on the page from the page content snapshot. If omitted takes a pages screenshot.'),
|
|
31
|
-
fullPage:
|
|
32
|
+
fullPage: zod
|
|
32
33
|
.boolean()
|
|
33
34
|
.optional()
|
|
34
35
|
.describe('If set to true takes a screenshot of the full page instead of the currently visible viewport. Incompatible with uid.'),
|
|
35
|
-
filePath:
|
|
36
|
+
filePath: zod
|
|
36
37
|
.string()
|
|
37
38
|
.optional()
|
|
38
39
|
.describe('The absolute path, or a path relative to the current working directory, to save the screenshot to instead of attaching it to the response.'),
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { zod } from '../third_party/index.js';
|
|
7
|
+
import { ToolCategory } from './categories.js';
|
|
3
8
|
import { defineTool } from './ToolDefinition.js';
|
|
4
9
|
export const evaluateScript = defineTool({
|
|
5
10
|
name: 'evaluate_script',
|
|
6
11
|
description: `Evaluate a JavaScript function inside the currently selected page. Returns the response as JSON
|
|
7
12
|
so returned values have to JSON-serializable.`,
|
|
8
13
|
annotations: {
|
|
9
|
-
category:
|
|
14
|
+
category: ToolCategory.DEBUGGING,
|
|
10
15
|
readOnlyHint: false,
|
|
11
16
|
},
|
|
12
17
|
schema: {
|
|
13
|
-
function:
|
|
18
|
+
function: zod.string().describe(`A JavaScript function declaration to be executed by the tool in the currently selected page.
|
|
14
19
|
Example without arguments: \`() => {
|
|
15
20
|
return document.title
|
|
16
21
|
}\` or \`async () => {
|
|
@@ -20,9 +25,9 @@ Example with arguments: \`(el) => {
|
|
|
20
25
|
return el.innerText;
|
|
21
26
|
}\`
|
|
22
27
|
`),
|
|
23
|
-
args:
|
|
24
|
-
.array(
|
|
25
|
-
uid:
|
|
28
|
+
args: zod
|
|
29
|
+
.array(zod.object({
|
|
30
|
+
uid: zod
|
|
26
31
|
.string()
|
|
27
32
|
.describe('The uid of an element on the page from the page content snapshot'),
|
|
28
33
|
}))
|
|
@@ -30,15 +35,26 @@ Example with arguments: \`(el) => {
|
|
|
30
35
|
.describe(`An optional list of arguments to pass to the function.`),
|
|
31
36
|
},
|
|
32
37
|
handler: async (request, response, context) => {
|
|
33
|
-
const
|
|
34
|
-
const fn = await page.evaluateHandle(`(${request.params.function})`);
|
|
35
|
-
const args = [fn];
|
|
38
|
+
const args = [];
|
|
36
39
|
try {
|
|
40
|
+
const frames = new Set();
|
|
37
41
|
for (const el of request.params.args ?? []) {
|
|
38
|
-
|
|
42
|
+
const handle = await context.getElementByUid(el.uid);
|
|
43
|
+
frames.add(handle.frame);
|
|
44
|
+
args.push(handle);
|
|
39
45
|
}
|
|
46
|
+
let pageOrFrame;
|
|
47
|
+
// We can't evaluate the element handle across frames
|
|
48
|
+
if (frames.size > 1) {
|
|
49
|
+
throw new Error("Elements from different frames can't be evaluated together.");
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
pageOrFrame = [...frames.values()][0] ?? context.getSelectedPage();
|
|
53
|
+
}
|
|
54
|
+
const fn = await pageOrFrame.evaluateHandle(`(${request.params.function})`);
|
|
55
|
+
args.unshift(fn);
|
|
40
56
|
await context.waitForEventsAfterAction(async () => {
|
|
41
|
-
const result = await
|
|
57
|
+
const result = await pageOrFrame.evaluate(async (fn, ...args) => {
|
|
42
58
|
// @ts-expect-error no types.
|
|
43
59
|
return JSON.stringify(await fn(...args));
|
|
44
60
|
}, ...args);
|
|
@@ -49,9 +65,7 @@ Example with arguments: \`(el) => {
|
|
|
49
65
|
});
|
|
50
66
|
}
|
|
51
67
|
finally {
|
|
52
|
-
Promise.allSettled(args.map(arg => arg.dispose()))
|
|
53
|
-
// Ignore errors
|
|
54
|
-
});
|
|
68
|
+
void Promise.allSettled(args.map(arg => arg.dispose()));
|
|
55
69
|
}
|
|
56
70
|
},
|
|
57
71
|
});
|
|
@@ -3,46 +3,50 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import { ToolCategories } from './categories.js';
|
|
6
|
+
import { zod } from '../third_party/index.js';
|
|
7
|
+
import { ToolCategory } from './categories.js';
|
|
9
8
|
import { defineTool, timeoutSchema } from './ToolDefinition.js';
|
|
10
9
|
export const takeSnapshot = defineTool({
|
|
11
10
|
name: 'take_snapshot',
|
|
12
|
-
description: `Take a text snapshot of the currently selected page. The snapshot lists page elements along with a unique
|
|
13
|
-
identifier (uid). Always use the latest snapshot. Prefer taking a snapshot over taking a screenshot
|
|
11
|
+
description: `Take a text snapshot of the currently selected page based on the a11y tree. The snapshot lists page elements along with a unique
|
|
12
|
+
identifier (uid). Always use the latest snapshot. Prefer taking a snapshot over taking a screenshot. The snapshot indicates the element selected
|
|
13
|
+
in the DevTools Elements panel (if any).`,
|
|
14
14
|
annotations: {
|
|
15
|
-
category:
|
|
16
|
-
|
|
15
|
+
category: ToolCategory.DEBUGGING,
|
|
16
|
+
// Not read-only due to filePath param.
|
|
17
|
+
readOnlyHint: false,
|
|
18
|
+
},
|
|
19
|
+
schema: {
|
|
20
|
+
verbose: zod
|
|
21
|
+
.boolean()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('Whether to include all possible information available in the full a11y tree. Default is false.'),
|
|
24
|
+
filePath: zod
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe('The absolute path, or a path relative to the current working directory, to save the snapshot to instead of attaching it to the response.'),
|
|
17
28
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
handler: async (request, response) => {
|
|
30
|
+
response.includeSnapshot({
|
|
31
|
+
verbose: request.params.verbose ?? false,
|
|
32
|
+
filePath: request.params.filePath,
|
|
33
|
+
});
|
|
21
34
|
},
|
|
22
35
|
});
|
|
23
36
|
export const waitFor = defineTool({
|
|
24
37
|
name: 'wait_for',
|
|
25
38
|
description: `Wait for the specified text to appear on the selected page.`,
|
|
26
39
|
annotations: {
|
|
27
|
-
category:
|
|
40
|
+
category: ToolCategory.NAVIGATION,
|
|
28
41
|
readOnlyHint: true,
|
|
29
42
|
},
|
|
30
43
|
schema: {
|
|
31
|
-
text:
|
|
44
|
+
text: zod.string().describe('Text to appear on the page'),
|
|
32
45
|
...timeoutSchema,
|
|
33
46
|
},
|
|
34
47
|
handler: async (request, response, context) => {
|
|
35
|
-
|
|
36
|
-
const frames = page.frames();
|
|
37
|
-
const locator = Locator.race(frames.flatMap(frame => [
|
|
38
|
-
frame.locator(`aria/${request.params.text}`),
|
|
39
|
-
frame.locator(`text/${request.params.text}`),
|
|
40
|
-
]));
|
|
41
|
-
if (request.params.timeout) {
|
|
42
|
-
locator.setTimeout(request.params.timeout);
|
|
43
|
-
}
|
|
44
|
-
await locator.wait();
|
|
48
|
+
await context.waitForTextOnPage(request.params);
|
|
45
49
|
response.appendResponseLine(`Element with text "${request.params.text}" found.`);
|
|
46
|
-
response.
|
|
50
|
+
response.includeSnapshot();
|
|
47
51
|
},
|
|
48
52
|
});
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { PerformanceInsightFormatter } from '../../node_modules/chrome-devtools-frontend/
|
|
7
|
-
import { PerformanceTraceFormatter } from '../../node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.js';
|
|
8
|
-
import { AgentFocus } from '../../node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AIContext.js';
|
|
9
|
-
import * as TraceEngine from '../../node_modules/chrome-devtools-frontend/front_end/models/trace/trace.js';
|
|
6
|
+
import { AgentFocus, TraceEngine, PerformanceTraceFormatter, PerformanceInsightFormatter, } from '../../node_modules/chrome-devtools-frontend/mcp/mcp.js';
|
|
10
7
|
import { logger } from '../logger.js';
|
|
11
8
|
const engine = TraceEngine.TraceModel.Model.createWithAllHandlers();
|
|
12
9
|
export function traceResultIsSuccess(x) {
|
|
@@ -64,26 +61,19 @@ ${summaryText}
|
|
|
64
61
|
## Details on call tree & network request formats:
|
|
65
62
|
${extraFormatDescriptions}`;
|
|
66
63
|
}
|
|
67
|
-
export function getInsightOutput(result, insightName) {
|
|
64
|
+
export function getInsightOutput(result, insightSetId, insightName) {
|
|
68
65
|
if (!result.insights) {
|
|
69
66
|
return {
|
|
70
67
|
error: 'No Performance insights are available for this trace.',
|
|
71
68
|
};
|
|
72
69
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// 2. Fall back to finding Insights not associated with a navigation (common case: user tests an interaction without a page load).
|
|
76
|
-
const mainNavigationId = result.parsedTrace.data.Meta.mainFrameNavigations.at(0)?.args.data
|
|
77
|
-
?.navigationId;
|
|
78
|
-
const insightsForNav = result.insights.get(mainNavigationId ?? TraceEngine.Types.Events.NO_NAVIGATION);
|
|
79
|
-
if (!insightsForNav) {
|
|
70
|
+
const insightSet = result.insights.get(insightSetId);
|
|
71
|
+
if (!insightSet) {
|
|
80
72
|
return {
|
|
81
|
-
error: 'No Performance Insights for
|
|
73
|
+
error: 'No Performance Insights for the given insight set id. Only use ids given in the "Available insight sets" list.',
|
|
82
74
|
};
|
|
83
75
|
}
|
|
84
|
-
const matchingInsight = insightName in
|
|
85
|
-
? insightsForNav.model[insightName]
|
|
86
|
-
: null;
|
|
76
|
+
const matchingInsight = insightName in insightSet.model ? insightSet.model[insightName] : null;
|
|
87
77
|
if (!matchingInsight) {
|
|
88
78
|
return {
|
|
89
79
|
error: `No Insight with the name ${insightName} found. Double check the name you provided is accurate and try again.`,
|