chrome-devtools-mcp 0.8.1 → 0.9.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 +58 -3
- 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/Settings.js +1 -1
- 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/UserMetrics.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/ConnectionTransport.js +12 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/protocol_client/InspectorBackend.js +15 -27
- package/build/node_modules/chrome-devtools-frontend/front_end/core/protocol_client/protocol_client.js +2 -8
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSMatchedStyles.js +42 -7
- 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/ChildTargetManager.js +3 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/Connections.js +2 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/DOMModel.js +3 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/DebuggerModel.js +2 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js +336 -40
- 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 +32 -7
- 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 +48 -11
- 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.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 +8 -6
- package/build/node_modules/chrome-devtools-frontend/front_end/generated/SupportedCSSProperties.js +16 -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/performance/AICallTree.js +2 -3
- 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/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/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/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/src/DevToolsConnectionAdapter.js +32 -0
- package/build/src/McpContext.js +70 -31
- package/build/src/McpResponse.js +145 -44
- package/build/src/PageCollector.js +110 -26
- package/build/src/WaitForHelper.js +5 -0
- package/build/src/browser.js +16 -4
- package/build/src/cli.js +82 -6
- package/build/src/formatters/consoleFormatter.js +29 -62
- package/build/src/formatters/networkFormatter.js +5 -6
- package/build/src/formatters/snapshotFormatter.js +10 -5
- package/build/src/logger.js +1 -1
- package/build/src/main.js +18 -5
- package/build/src/polyfill.js +2 -2
- package/build/src/third_party/THIRD_PARTY_NOTICES +1393 -0
- package/build/src/third_party/index.js +76159 -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 +6 -7
- package/build/src/tools/input.js +21 -21
- package/build/src/tools/network.js +18 -10
- package/build/src/tools/pages.js +19 -19
- package/build/src/tools/performance.js +8 -8
- package/build/src/tools/screenshot.js +8 -8
- package/build/src/tools/script.js +29 -15
- package/build/src/tools/snapshot.js +15 -20
- package/build/src/utils/types.js +6 -0
- package/package.json +16 -13
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
6
|
+
import { zod } from '../third_party/index.js';
|
|
7
7
|
export function defineTool(definition) {
|
|
8
8
|
return definition;
|
|
9
9
|
}
|
|
10
10
|
export const CLOSE_PAGE_ERROR = 'The last open page cannot be closed. It is fine to keep it open.';
|
|
11
11
|
export const timeoutSchema = {
|
|
12
|
-
timeout:
|
|
12
|
+
timeout: zod
|
|
13
13
|
.number()
|
|
14
14
|
.int()
|
|
15
15
|
.optional()
|
|
@@ -3,12 +3,20 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
export var
|
|
7
|
-
(function (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})(
|
|
6
|
+
export var ToolCategory;
|
|
7
|
+
(function (ToolCategory) {
|
|
8
|
+
ToolCategory["INPUT"] = "input";
|
|
9
|
+
ToolCategory["NAVIGATION"] = "navigation";
|
|
10
|
+
ToolCategory["EMULATION"] = "emulation";
|
|
11
|
+
ToolCategory["PERFORMANCE"] = "performance";
|
|
12
|
+
ToolCategory["NETWORK"] = "network";
|
|
13
|
+
ToolCategory["DEBUGGING"] = "debugging";
|
|
14
|
+
})(ToolCategory || (ToolCategory = {}));
|
|
15
|
+
export const labels = {
|
|
16
|
+
[ToolCategory.INPUT]: 'Input automation',
|
|
17
|
+
[ToolCategory.NAVIGATION]: 'Navigation automation',
|
|
18
|
+
[ToolCategory.EMULATION]: 'Emulation',
|
|
19
|
+
[ToolCategory.PERFORMANCE]: 'Performance',
|
|
20
|
+
[ToolCategory.NETWORK]: 'Network',
|
|
21
|
+
[ToolCategory.DEBUGGING]: 'Debugging',
|
|
22
|
+
};
|
|
@@ -3,17 +3,82 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { zod } from '../third_party/index.js';
|
|
7
|
+
import { ToolCategory } from './categories.js';
|
|
7
8
|
import { defineTool } from './ToolDefinition.js';
|
|
8
|
-
|
|
9
|
+
const FILTERABLE_MESSAGE_TYPES = [
|
|
10
|
+
'log',
|
|
11
|
+
'debug',
|
|
12
|
+
'info',
|
|
13
|
+
'error',
|
|
14
|
+
'warn',
|
|
15
|
+
'dir',
|
|
16
|
+
'dirxml',
|
|
17
|
+
'table',
|
|
18
|
+
'trace',
|
|
19
|
+
'clear',
|
|
20
|
+
'startGroup',
|
|
21
|
+
'startGroupCollapsed',
|
|
22
|
+
'endGroup',
|
|
23
|
+
'assert',
|
|
24
|
+
'profile',
|
|
25
|
+
'profileEnd',
|
|
26
|
+
'count',
|
|
27
|
+
'timeEnd',
|
|
28
|
+
'verbose',
|
|
29
|
+
];
|
|
30
|
+
export const listConsoleMessages = defineTool({
|
|
9
31
|
name: 'list_console_messages',
|
|
10
32
|
description: 'List all console messages for the currently selected page since the last navigation.',
|
|
11
33
|
annotations: {
|
|
12
|
-
category:
|
|
34
|
+
category: ToolCategory.DEBUGGING,
|
|
13
35
|
readOnlyHint: true,
|
|
14
36
|
},
|
|
15
|
-
schema: {
|
|
16
|
-
|
|
17
|
-
|
|
37
|
+
schema: {
|
|
38
|
+
pageSize: zod
|
|
39
|
+
.number()
|
|
40
|
+
.int()
|
|
41
|
+
.positive()
|
|
42
|
+
.optional()
|
|
43
|
+
.describe('Maximum number of messages to return. When omitted, returns all requests.'),
|
|
44
|
+
pageIdx: zod
|
|
45
|
+
.number()
|
|
46
|
+
.int()
|
|
47
|
+
.min(0)
|
|
48
|
+
.optional()
|
|
49
|
+
.describe('Page number to return (0-based). When omitted, returns the first page.'),
|
|
50
|
+
types: zod
|
|
51
|
+
.array(zod.enum(FILTERABLE_MESSAGE_TYPES))
|
|
52
|
+
.optional()
|
|
53
|
+
.describe('Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages.'),
|
|
54
|
+
includePreservedMessages: zod
|
|
55
|
+
.boolean()
|
|
56
|
+
.default(false)
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('Set to true to return the preserved messages over the last 3 navigations.'),
|
|
59
|
+
},
|
|
60
|
+
handler: async (request, response) => {
|
|
61
|
+
response.setIncludeConsoleData(true, {
|
|
62
|
+
pageSize: request.params.pageSize,
|
|
63
|
+
pageIdx: request.params.pageIdx,
|
|
64
|
+
types: request.params.types,
|
|
65
|
+
includePreservedMessages: request.params.includePreservedMessages,
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
export const getConsoleMessage = defineTool({
|
|
70
|
+
name: 'get_console_message',
|
|
71
|
+
description: `Gets a console message by its ID. You can get all messages by calling ${listConsoleMessages.name}.`,
|
|
72
|
+
annotations: {
|
|
73
|
+
category: ToolCategory.DEBUGGING,
|
|
74
|
+
readOnlyHint: true,
|
|
75
|
+
},
|
|
76
|
+
schema: {
|
|
77
|
+
msgid: zod
|
|
78
|
+
.number()
|
|
79
|
+
.describe('The msgid of a console message on the page from the listed console messages'),
|
|
80
|
+
},
|
|
81
|
+
handler: async (request, response) => {
|
|
82
|
+
response.attachConsoleMessage(request.params.msgid);
|
|
18
83
|
},
|
|
19
84
|
});
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { PredefinedNetworkConditions } from '
|
|
7
|
-
import
|
|
8
|
-
import { ToolCategories } from './categories.js';
|
|
6
|
+
import { zod, PredefinedNetworkConditions } from '../third_party/index.js';
|
|
7
|
+
import { ToolCategory } from './categories.js';
|
|
9
8
|
import { defineTool } from './ToolDefinition.js';
|
|
10
9
|
const throttlingOptions = [
|
|
11
10
|
'No emulation',
|
|
@@ -16,11 +15,11 @@ export const emulateNetwork = defineTool({
|
|
|
16
15
|
name: 'emulate_network',
|
|
17
16
|
description: `Emulates network conditions such as throttling or offline mode on the selected page.`,
|
|
18
17
|
annotations: {
|
|
19
|
-
category:
|
|
18
|
+
category: ToolCategory.EMULATION,
|
|
20
19
|
readOnlyHint: false,
|
|
21
20
|
},
|
|
22
21
|
schema: {
|
|
23
|
-
throttlingOption:
|
|
22
|
+
throttlingOption: zod
|
|
24
23
|
.enum(throttlingOptions)
|
|
25
24
|
.describe(`The network throttling option to emulate. Available throttling options are: ${throttlingOptions.join(', ')}. Set to "No emulation" to disable. Set to "Offline" to simulate offline network conditions.`),
|
|
26
25
|
},
|
|
@@ -53,11 +52,11 @@ export const emulateCpu = defineTool({
|
|
|
53
52
|
name: 'emulate_cpu',
|
|
54
53
|
description: `Emulates CPU throttling by slowing down the selected page's execution.`,
|
|
55
54
|
annotations: {
|
|
56
|
-
category:
|
|
55
|
+
category: ToolCategory.EMULATION,
|
|
57
56
|
readOnlyHint: false,
|
|
58
57
|
},
|
|
59
58
|
schema: {
|
|
60
|
-
throttlingRate:
|
|
59
|
+
throttlingRate: zod
|
|
61
60
|
.number()
|
|
62
61
|
.min(1)
|
|
63
62
|
.max(20)
|
package/build/src/tools/input.js
CHANGED
|
@@ -3,21 +3,21 @@
|
|
|
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 click = defineTool({
|
|
10
10
|
name: 'click',
|
|
11
11
|
description: `Clicks on the provided element`,
|
|
12
12
|
annotations: {
|
|
13
|
-
category:
|
|
13
|
+
category: ToolCategory.INPUT,
|
|
14
14
|
readOnlyHint: false,
|
|
15
15
|
},
|
|
16
16
|
schema: {
|
|
17
|
-
uid:
|
|
17
|
+
uid: zod
|
|
18
18
|
.string()
|
|
19
19
|
.describe('The uid of an element on the page from the page content snapshot'),
|
|
20
|
-
dblClick:
|
|
20
|
+
dblClick: zod
|
|
21
21
|
.boolean()
|
|
22
22
|
.optional()
|
|
23
23
|
.describe('Set to true for double clicks. Default is false.'),
|
|
@@ -45,11 +45,11 @@ export const hover = defineTool({
|
|
|
45
45
|
name: 'hover',
|
|
46
46
|
description: `Hover over the provided element`,
|
|
47
47
|
annotations: {
|
|
48
|
-
category:
|
|
48
|
+
category: ToolCategory.INPUT,
|
|
49
49
|
readOnlyHint: false,
|
|
50
50
|
},
|
|
51
51
|
schema: {
|
|
52
|
-
uid:
|
|
52
|
+
uid: zod
|
|
53
53
|
.string()
|
|
54
54
|
.describe('The uid of an element on the page from the page content snapshot'),
|
|
55
55
|
},
|
|
@@ -121,14 +121,14 @@ export const fill = defineTool({
|
|
|
121
121
|
name: 'fill',
|
|
122
122
|
description: `Type text into a input, text area or select an option from a <select> element.`,
|
|
123
123
|
annotations: {
|
|
124
|
-
category:
|
|
124
|
+
category: ToolCategory.INPUT,
|
|
125
125
|
readOnlyHint: false,
|
|
126
126
|
},
|
|
127
127
|
schema: {
|
|
128
|
-
uid:
|
|
128
|
+
uid: zod
|
|
129
129
|
.string()
|
|
130
130
|
.describe('The uid of an element on the page from the page content snapshot'),
|
|
131
|
-
value:
|
|
131
|
+
value: zod.string().describe('The value to fill in'),
|
|
132
132
|
},
|
|
133
133
|
handler: async (request, response, context) => {
|
|
134
134
|
await context.waitForEventsAfterAction(async () => {
|
|
@@ -142,12 +142,12 @@ export const drag = defineTool({
|
|
|
142
142
|
name: 'drag',
|
|
143
143
|
description: `Drag an element onto another element`,
|
|
144
144
|
annotations: {
|
|
145
|
-
category:
|
|
145
|
+
category: ToolCategory.INPUT,
|
|
146
146
|
readOnlyHint: false,
|
|
147
147
|
},
|
|
148
148
|
schema: {
|
|
149
|
-
from_uid:
|
|
150
|
-
to_uid:
|
|
149
|
+
from_uid: zod.string().describe('The uid of the element to drag'),
|
|
150
|
+
to_uid: zod.string().describe('The uid of the element to drop into'),
|
|
151
151
|
},
|
|
152
152
|
handler: async (request, response, context) => {
|
|
153
153
|
const fromHandle = await context.getElementByUid(request.params.from_uid);
|
|
@@ -171,14 +171,14 @@ export const fillForm = defineTool({
|
|
|
171
171
|
name: 'fill_form',
|
|
172
172
|
description: `Fill out multiple form elements at once`,
|
|
173
173
|
annotations: {
|
|
174
|
-
category:
|
|
174
|
+
category: ToolCategory.INPUT,
|
|
175
175
|
readOnlyHint: false,
|
|
176
176
|
},
|
|
177
177
|
schema: {
|
|
178
|
-
elements:
|
|
179
|
-
.array(
|
|
180
|
-
uid:
|
|
181
|
-
value:
|
|
178
|
+
elements: zod
|
|
179
|
+
.array(zod.object({
|
|
180
|
+
uid: zod.string().describe('The uid of the element to fill out'),
|
|
181
|
+
value: zod.string().describe('Value for the element'),
|
|
182
182
|
}))
|
|
183
183
|
.describe('Elements from snapshot to fill out.'),
|
|
184
184
|
},
|
|
@@ -196,14 +196,14 @@ export const uploadFile = defineTool({
|
|
|
196
196
|
name: 'upload_file',
|
|
197
197
|
description: 'Upload a file through a provided element.',
|
|
198
198
|
annotations: {
|
|
199
|
-
category:
|
|
199
|
+
category: ToolCategory.INPUT,
|
|
200
200
|
readOnlyHint: false,
|
|
201
201
|
},
|
|
202
202
|
schema: {
|
|
203
|
-
uid:
|
|
203
|
+
uid: zod
|
|
204
204
|
.string()
|
|
205
205
|
.describe('The uid of the file input element or an element that will open file chooser on the page from the page content snapshot'),
|
|
206
|
-
filePath:
|
|
206
|
+
filePath: zod.string().describe('The local path of the file to upload'),
|
|
207
207
|
},
|
|
208
208
|
handler: async (request, response, context) => {
|
|
209
209
|
const { uid, filePath } = request.params;
|
|
@@ -3,8 +3,8 @@
|
|
|
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
|
const FILTERABLE_RESOURCE_TYPES = [
|
|
10
10
|
'document',
|
|
@@ -31,32 +31,38 @@ export const listNetworkRequests = defineTool({
|
|
|
31
31
|
name: 'list_network_requests',
|
|
32
32
|
description: `List all requests for the currently selected page since the last navigation.`,
|
|
33
33
|
annotations: {
|
|
34
|
-
category:
|
|
34
|
+
category: ToolCategory.NETWORK,
|
|
35
35
|
readOnlyHint: true,
|
|
36
36
|
},
|
|
37
37
|
schema: {
|
|
38
|
-
pageSize:
|
|
38
|
+
pageSize: zod
|
|
39
39
|
.number()
|
|
40
40
|
.int()
|
|
41
41
|
.positive()
|
|
42
42
|
.optional()
|
|
43
43
|
.describe('Maximum number of requests to return. When omitted, returns all requests.'),
|
|
44
|
-
pageIdx:
|
|
44
|
+
pageIdx: zod
|
|
45
45
|
.number()
|
|
46
46
|
.int()
|
|
47
47
|
.min(0)
|
|
48
48
|
.optional()
|
|
49
49
|
.describe('Page number to return (0-based). When omitted, returns the first page.'),
|
|
50
|
-
resourceTypes:
|
|
51
|
-
.array(
|
|
50
|
+
resourceTypes: zod
|
|
51
|
+
.array(zod.enum(FILTERABLE_RESOURCE_TYPES))
|
|
52
52
|
.optional()
|
|
53
53
|
.describe('Filter requests to only return requests of the specified resource types. When omitted or empty, returns all requests.'),
|
|
54
|
+
includePreservedRequests: zod
|
|
55
|
+
.boolean()
|
|
56
|
+
.default(false)
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('Set to true to return the preserved requests over the last 3 navigations.'),
|
|
54
59
|
},
|
|
55
60
|
handler: async (request, response) => {
|
|
56
61
|
response.setIncludeNetworkRequests(true, {
|
|
57
62
|
pageSize: request.params.pageSize,
|
|
58
63
|
pageIdx: request.params.pageIdx,
|
|
59
64
|
resourceTypes: request.params.resourceTypes,
|
|
65
|
+
includePreservedRequests: request.params.includePreservedRequests,
|
|
60
66
|
});
|
|
61
67
|
},
|
|
62
68
|
});
|
|
@@ -64,13 +70,15 @@ export const getNetworkRequest = defineTool({
|
|
|
64
70
|
name: 'get_network_request',
|
|
65
71
|
description: `Gets a network request by URL. You can get all requests by calling ${listNetworkRequests.name}.`,
|
|
66
72
|
annotations: {
|
|
67
|
-
category:
|
|
73
|
+
category: ToolCategory.NETWORK,
|
|
68
74
|
readOnlyHint: true,
|
|
69
75
|
},
|
|
70
76
|
schema: {
|
|
71
|
-
|
|
77
|
+
reqid: zod
|
|
78
|
+
.number()
|
|
79
|
+
.describe('The reqid of a request on the page from the listed network requests'),
|
|
72
80
|
},
|
|
73
81
|
handler: async (request, response, _context) => {
|
|
74
|
-
response.attachNetworkRequest(request.params.
|
|
82
|
+
response.attachNetworkRequest(request.params.reqid);
|
|
75
83
|
},
|
|
76
84
|
});
|
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,11 +90,11 @@ 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
|
-
url:
|
|
97
|
+
url: zod.string().describe('URL to navigate the page to'),
|
|
98
98
|
...timeoutSchema,
|
|
99
99
|
},
|
|
100
100
|
handler: async (request, response, context) => {
|
|
@@ -111,11 +111,11 @@ export const navigatePageHistory = defineTool({
|
|
|
111
111
|
name: 'navigate_page_history',
|
|
112
112
|
description: `Navigates the currently selected page.`,
|
|
113
113
|
annotations: {
|
|
114
|
-
category:
|
|
114
|
+
category: ToolCategory.NAVIGATION,
|
|
115
115
|
readOnlyHint: false,
|
|
116
116
|
},
|
|
117
117
|
schema: {
|
|
118
|
-
navigate:
|
|
118
|
+
navigate: zod
|
|
119
119
|
.enum(['back', 'forward'])
|
|
120
120
|
.describe('Whether to navigate back or navigate forward in the selected pages history'),
|
|
121
121
|
...timeoutSchema,
|
|
@@ -143,12 +143,12 @@ export const resizePage = defineTool({
|
|
|
143
143
|
name: 'resize_page',
|
|
144
144
|
description: `Resizes the selected page's window so that the page has specified dimension`,
|
|
145
145
|
annotations: {
|
|
146
|
-
category:
|
|
146
|
+
category: ToolCategory.EMULATION,
|
|
147
147
|
readOnlyHint: false,
|
|
148
148
|
},
|
|
149
149
|
schema: {
|
|
150
|
-
width:
|
|
151
|
-
height:
|
|
150
|
+
width: zod.number().describe('Page width'),
|
|
151
|
+
height: zod.number().describe('Page height'),
|
|
152
152
|
},
|
|
153
153
|
handler: async (request, response, context) => {
|
|
154
154
|
const page = context.getSelectedPage();
|
|
@@ -164,14 +164,14 @@ export const handleDialog = defineTool({
|
|
|
164
164
|
name: 'handle_dialog',
|
|
165
165
|
description: `If a browser dialog was opened, use this command to handle it`,
|
|
166
166
|
annotations: {
|
|
167
|
-
category:
|
|
167
|
+
category: ToolCategory.INPUT,
|
|
168
168
|
readOnlyHint: false,
|
|
169
169
|
},
|
|
170
170
|
schema: {
|
|
171
|
-
action:
|
|
171
|
+
action: zod
|
|
172
172
|
.enum(['accept', 'dismiss'])
|
|
173
173
|
.describe('Whether to dismiss or accept the dialog'),
|
|
174
|
-
promptText:
|
|
174
|
+
promptText: zod
|
|
175
175
|
.string()
|
|
176
176
|
.optional()
|
|
177
177
|
.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: {},
|
|
@@ -95,11 +95,11 @@ export const analyzeInsight = defineTool({
|
|
|
95
95
|
name: 'performance_analyze_insight',
|
|
96
96
|
description: 'Provides more detailed information on a specific Performance Insight 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
|
-
insightName:
|
|
102
|
+
insightName: zod
|
|
103
103
|
.string()
|
|
104
104
|
.describe('The name of the Insight you want more information on. For example: "DocumentLatency" or "LCPBreakdown"'),
|
|
105
105
|
},
|
|
@@ -3,36 +3,36 @@
|
|
|
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:
|
|
13
|
+
category: ToolCategory.DEBUGGING,
|
|
14
14
|
readOnlyHint: true,
|
|
15
15
|
},
|
|
16
16
|
schema: {
|
|
17
|
-
format:
|
|
17
|
+
format: zod
|
|
18
18
|
.enum(['png', 'jpeg', 'webp'])
|
|
19
19
|
.default('png')
|
|
20
20
|
.describe('Type of format to save the screenshot as. Default is "png"'),
|
|
21
|
-
quality:
|
|
21
|
+
quality: zod
|
|
22
22
|
.number()
|
|
23
23
|
.min(0)
|
|
24
24
|
.max(100)
|
|
25
25
|
.optional()
|
|
26
26
|
.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:
|
|
27
|
+
uid: zod
|
|
28
28
|
.string()
|
|
29
29
|
.optional()
|
|
30
30
|
.describe('The uid of an element on the page from the page content snapshot. If omitted takes a pages screenshot.'),
|
|
31
|
-
fullPage:
|
|
31
|
+
fullPage: zod
|
|
32
32
|
.boolean()
|
|
33
33
|
.optional()
|
|
34
34
|
.describe('If set to true takes a screenshot of the full page instead of the currently visible viewport. Incompatible with uid.'),
|
|
35
|
-
filePath:
|
|
35
|
+
filePath: zod
|
|
36
36
|
.string()
|
|
37
37
|
.optional()
|
|
38
38
|
.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
|
});
|