@mcp-b/chrome-devtools-mcp 2.3.0 → 2.3.1-beta.20260528050333
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/package.json +1 -1
- package/build/src/DevToolsConnectionAdapter.js +0 -70
- package/build/src/DevtoolsUtils.js +0 -290
- package/build/src/McpContext.js +0 -687
- package/build/src/McpPage.js +0 -95
- package/build/src/McpResponse.js +0 -588
- package/build/src/Mutex.js +0 -37
- package/build/src/PageCollector.js +0 -308
- package/build/src/SlimMcpResponse.js +0 -18
- package/build/src/WaitForHelper.js +0 -135
- package/build/src/bin/chrome-devtools-cli-options.js +0 -651
- package/build/src/bin/chrome-devtools-mcp-cli-options.js +0 -317
- package/build/src/bin/chrome-devtools-mcp-main.js +0 -35
- package/build/src/bin/chrome-devtools-mcp.js +0 -21
- package/build/src/bin/chrome-devtools.js +0 -185
- package/build/src/bin/cliDefinitions.js +0 -615
- package/build/src/browser.js +0 -198
- package/build/src/daemon/client.js +0 -152
- package/build/src/daemon/daemon.js +0 -206
- package/build/src/daemon/types.js +0 -6
- package/build/src/daemon/utils.js +0 -108
- package/build/src/formatters/ConsoleFormatter.js +0 -234
- package/build/src/formatters/IssueFormatter.js +0 -192
- package/build/src/formatters/NetworkFormatter.js +0 -215
- package/build/src/formatters/SnapshotFormatter.js +0 -131
- package/build/src/index.js +0 -202
- package/build/src/issue-descriptions.js +0 -39
- package/build/src/logger.js +0 -36
- package/build/src/polyfill.js +0 -7
- package/build/src/telemetry/ClearcutLogger.js +0 -102
- package/build/src/telemetry/WatchdogClient.js +0 -60
- package/build/src/telemetry/flagUtils.js +0 -45
- package/build/src/telemetry/metricUtils.js +0 -14
- package/build/src/telemetry/persistence.js +0 -53
- package/build/src/telemetry/types.js +0 -33
- package/build/src/telemetry/watchdog/ClearcutSender.js +0 -203
- package/build/src/telemetry/watchdog/main.js +0 -127
- package/build/src/third_party/devtools-formatter-worker.js +0 -7
- package/build/src/third_party/index.js +0 -26
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +0 -54183
- package/build/src/tools/ToolDefinition.js +0 -72
- package/build/src/tools/categories.js +0 -24
- package/build/src/tools/console.js +0 -85
- package/build/src/tools/emulation.js +0 -55
- package/build/src/tools/extensions.js +0 -96
- package/build/src/tools/input.js +0 -368
- package/build/src/tools/lighthouse.js +0 -123
- package/build/src/tools/memory.js +0 -28
- package/build/src/tools/network.js +0 -120
- package/build/src/tools/pages.js +0 -319
- package/build/src/tools/performance.js +0 -190
- package/build/src/tools/screencast.js +0 -79
- package/build/src/tools/screenshot.js +0 -84
- package/build/src/tools/script.js +0 -119
- package/build/src/tools/slim/tools.js +0 -81
- package/build/src/tools/snapshot.js +0 -56
- package/build/src/tools/tools.js +0 -52
- package/build/src/tools/webmcp.js +0 -416
- package/build/src/trace-processing/parse.js +0 -84
- package/build/src/types.js +0 -6
- package/build/src/utils/ExtensionRegistry.js +0 -35
- package/build/src/utils/files.js +0 -19
- package/build/src/utils/keyboard.js +0 -296
- package/build/src/utils/pagination.js +0 -49
- package/build/src/utils/string.js +0 -36
- package/build/src/utils/types.js +0 -6
- package/build/src/version.js +0 -9
package/build/src/tools/input.js
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
import { logger } from '../logger.js';
|
|
7
|
-
import { zod } from '../third_party/index.js';
|
|
8
|
-
import { parseKey } from '../utils/keyboard.js';
|
|
9
|
-
import { ToolCategory } from './categories.js';
|
|
10
|
-
import { definePageTool } from './ToolDefinition.js';
|
|
11
|
-
const dblClickSchema = zod
|
|
12
|
-
.boolean()
|
|
13
|
-
.optional()
|
|
14
|
-
.describe('Set to true for double clicks. Default is false.');
|
|
15
|
-
const includeSnapshotSchema = zod
|
|
16
|
-
.boolean()
|
|
17
|
-
.optional()
|
|
18
|
-
.describe('Whether to include a snapshot in the response. Default is false.');
|
|
19
|
-
const submitKeySchema = zod
|
|
20
|
-
.string()
|
|
21
|
-
.optional()
|
|
22
|
-
.describe('Optional key to press after typing. E.g., "Enter", "Tab", "Escape"');
|
|
23
|
-
function handleActionError(error, uid) {
|
|
24
|
-
logger('failed to act using a locator', error);
|
|
25
|
-
throw new Error(`Failed to interact with the element with uid ${uid}. The element did not become interactive within the configured timeout.`, {
|
|
26
|
-
cause: error,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
export const click = definePageTool({
|
|
30
|
-
name: 'click',
|
|
31
|
-
description: `Clicks on the provided element`,
|
|
32
|
-
annotations: {
|
|
33
|
-
category: ToolCategory.INPUT,
|
|
34
|
-
readOnlyHint: false,
|
|
35
|
-
},
|
|
36
|
-
schema: {
|
|
37
|
-
uid: zod.string().describe('The uid of an element on the page from the page content snapshot'),
|
|
38
|
-
dblClick: dblClickSchema,
|
|
39
|
-
includeSnapshot: includeSnapshotSchema,
|
|
40
|
-
},
|
|
41
|
-
handler: async (request, response, context) => {
|
|
42
|
-
const uid = request.params.uid;
|
|
43
|
-
const handle = await request.page.getElementByUid(uid);
|
|
44
|
-
try {
|
|
45
|
-
await context.waitForEventsAfterAction(async () => {
|
|
46
|
-
await handle.asLocator().click({
|
|
47
|
-
count: request.params.dblClick ? 2 : 1,
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
response.appendResponseLine(request.params.dblClick
|
|
51
|
-
? `Successfully double clicked on the element`
|
|
52
|
-
: `Successfully clicked on the element`);
|
|
53
|
-
if (request.params.includeSnapshot) {
|
|
54
|
-
response.includeSnapshot();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
handleActionError(error, uid);
|
|
59
|
-
}
|
|
60
|
-
finally {
|
|
61
|
-
void handle.dispose();
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
export const clickAt = definePageTool({
|
|
66
|
-
name: 'click_at',
|
|
67
|
-
description: `Clicks at the provided coordinates`,
|
|
68
|
-
annotations: {
|
|
69
|
-
category: ToolCategory.INPUT,
|
|
70
|
-
readOnlyHint: false,
|
|
71
|
-
conditions: ['computerVision'],
|
|
72
|
-
},
|
|
73
|
-
schema: {
|
|
74
|
-
x: zod.number().describe('The x coordinate'),
|
|
75
|
-
y: zod.number().describe('The y coordinate'),
|
|
76
|
-
dblClick: dblClickSchema,
|
|
77
|
-
includeSnapshot: includeSnapshotSchema,
|
|
78
|
-
},
|
|
79
|
-
handler: async (request, response, context) => {
|
|
80
|
-
const page = request.page;
|
|
81
|
-
await context.waitForEventsAfterAction(async () => {
|
|
82
|
-
await page.pptrPage.mouse.click(request.params.x, request.params.y, {
|
|
83
|
-
clickCount: request.params.dblClick ? 2 : 1,
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
response.appendResponseLine(request.params.dblClick
|
|
87
|
-
? `Successfully double clicked at the coordinates`
|
|
88
|
-
: `Successfully clicked at the coordinates`);
|
|
89
|
-
if (request.params.includeSnapshot) {
|
|
90
|
-
response.includeSnapshot();
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
export const hover = definePageTool({
|
|
95
|
-
name: 'hover',
|
|
96
|
-
description: `Hover over the provided element`,
|
|
97
|
-
annotations: {
|
|
98
|
-
category: ToolCategory.INPUT,
|
|
99
|
-
readOnlyHint: false,
|
|
100
|
-
},
|
|
101
|
-
schema: {
|
|
102
|
-
uid: zod.string().describe('The uid of an element on the page from the page content snapshot'),
|
|
103
|
-
includeSnapshot: includeSnapshotSchema,
|
|
104
|
-
},
|
|
105
|
-
handler: async (request, response, context) => {
|
|
106
|
-
const uid = request.params.uid;
|
|
107
|
-
const handle = await request.page.getElementByUid(uid);
|
|
108
|
-
try {
|
|
109
|
-
await context.waitForEventsAfterAction(async () => {
|
|
110
|
-
await handle.asLocator().hover();
|
|
111
|
-
});
|
|
112
|
-
response.appendResponseLine(`Successfully hovered over the element`);
|
|
113
|
-
if (request.params.includeSnapshot) {
|
|
114
|
-
response.includeSnapshot();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
handleActionError(error, uid);
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
void handle.dispose();
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
// The AXNode for an option doesn't contain its `value`. We set text content of the option as value.
|
|
126
|
-
// If the form is a combobox, we need to find the correct option by its text value.
|
|
127
|
-
// To do that, loop through the children while checking which child's text matches the requested value (requested value is actually the text content).
|
|
128
|
-
// When the correct option is found, use the element handle to get the real value.
|
|
129
|
-
async function selectOption(handle, aXNode, value) {
|
|
130
|
-
let optionFound = false;
|
|
131
|
-
for (const child of aXNode.children) {
|
|
132
|
-
if (child.role === 'option' && child.name === value && child.value) {
|
|
133
|
-
optionFound = true;
|
|
134
|
-
const childHandle = await child.elementHandle();
|
|
135
|
-
if (childHandle) {
|
|
136
|
-
try {
|
|
137
|
-
const childValueHandle = await childHandle.getProperty('value');
|
|
138
|
-
try {
|
|
139
|
-
const childValue = await childValueHandle.jsonValue();
|
|
140
|
-
if (childValue) {
|
|
141
|
-
await handle.asLocator().fill(childValue.toString());
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
finally {
|
|
145
|
-
void childValueHandle.dispose();
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
finally {
|
|
150
|
-
void childHandle.dispose();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (!optionFound) {
|
|
156
|
-
throw new Error(`Could not find option with text "${value}"`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function hasOptionChildren(aXNode) {
|
|
160
|
-
return aXNode.children.some((child) => child.role === 'option');
|
|
161
|
-
}
|
|
162
|
-
async function fillFormElement(uid, value, context, page) {
|
|
163
|
-
const handle = await page.getElementByUid(uid);
|
|
164
|
-
try {
|
|
165
|
-
const aXNode = context.getAXNodeByUid(uid);
|
|
166
|
-
// We assume that combobox needs to be handled as select if it has
|
|
167
|
-
// role='combobox' and option children.
|
|
168
|
-
if (aXNode && aXNode.role === 'combobox' && hasOptionChildren(aXNode)) {
|
|
169
|
-
await selectOption(handle, aXNode, value);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
// Increase timeout for longer input values.
|
|
173
|
-
const timeoutPerChar = 10; // ms
|
|
174
|
-
const fillTimeout = page.pptrPage.getDefaultTimeout() + value.length * timeoutPerChar;
|
|
175
|
-
await handle.asLocator().setTimeout(fillTimeout).fill(value);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (error) {
|
|
179
|
-
handleActionError(error, uid);
|
|
180
|
-
}
|
|
181
|
-
finally {
|
|
182
|
-
void handle.dispose();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
export const fill = definePageTool({
|
|
186
|
-
name: 'fill',
|
|
187
|
-
description: `Type text into a input, text area or select an option from a <select> element.`,
|
|
188
|
-
annotations: {
|
|
189
|
-
category: ToolCategory.INPUT,
|
|
190
|
-
readOnlyHint: false,
|
|
191
|
-
},
|
|
192
|
-
schema: {
|
|
193
|
-
uid: zod.string().describe('The uid of an element on the page from the page content snapshot'),
|
|
194
|
-
value: zod.string().describe('The value to fill in'),
|
|
195
|
-
includeSnapshot: includeSnapshotSchema,
|
|
196
|
-
},
|
|
197
|
-
handler: async (request, response, context) => {
|
|
198
|
-
const page = request.page;
|
|
199
|
-
await context.waitForEventsAfterAction(async () => {
|
|
200
|
-
await fillFormElement(request.params.uid, request.params.value, context, page);
|
|
201
|
-
});
|
|
202
|
-
response.appendResponseLine(`Successfully filled out the element`);
|
|
203
|
-
if (request.params.includeSnapshot) {
|
|
204
|
-
response.includeSnapshot();
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
export const typeText = definePageTool({
|
|
209
|
-
name: 'type_text',
|
|
210
|
-
description: `Type text using keyboard into a previously focused input`,
|
|
211
|
-
annotations: {
|
|
212
|
-
category: ToolCategory.INPUT,
|
|
213
|
-
readOnlyHint: false,
|
|
214
|
-
},
|
|
215
|
-
schema: {
|
|
216
|
-
text: zod.string().describe('The text to type'),
|
|
217
|
-
submitKey: submitKeySchema,
|
|
218
|
-
},
|
|
219
|
-
handler: async (request, response, context) => {
|
|
220
|
-
const page = request.page;
|
|
221
|
-
await context.waitForEventsAfterAction(async () => {
|
|
222
|
-
await page.pptrPage.keyboard.type(request.params.text);
|
|
223
|
-
if (request.params.submitKey) {
|
|
224
|
-
await page.pptrPage.keyboard.press(request.params.submitKey);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
response.appendResponseLine(`Typed text "${request.params.text}${request.params.submitKey ? ` + ${request.params.submitKey}` : ''}"`);
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
export const drag = definePageTool({
|
|
231
|
-
name: 'drag',
|
|
232
|
-
description: `Drag an element onto another element`,
|
|
233
|
-
annotations: {
|
|
234
|
-
category: ToolCategory.INPUT,
|
|
235
|
-
readOnlyHint: false,
|
|
236
|
-
},
|
|
237
|
-
schema: {
|
|
238
|
-
from_uid: zod.string().describe('The uid of the element to drag'),
|
|
239
|
-
to_uid: zod.string().describe('The uid of the element to drop into'),
|
|
240
|
-
includeSnapshot: includeSnapshotSchema,
|
|
241
|
-
},
|
|
242
|
-
handler: async (request, response, context) => {
|
|
243
|
-
const fromHandle = await request.page.getElementByUid(request.params.from_uid);
|
|
244
|
-
const toHandle = await request.page.getElementByUid(request.params.to_uid);
|
|
245
|
-
try {
|
|
246
|
-
await context.waitForEventsAfterAction(async () => {
|
|
247
|
-
await fromHandle.drag(toHandle);
|
|
248
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
249
|
-
await toHandle.drop(fromHandle);
|
|
250
|
-
});
|
|
251
|
-
response.appendResponseLine(`Successfully dragged an element`);
|
|
252
|
-
if (request.params.includeSnapshot) {
|
|
253
|
-
response.includeSnapshot();
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
finally {
|
|
257
|
-
void fromHandle.dispose();
|
|
258
|
-
void toHandle.dispose();
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
export const fillForm = definePageTool({
|
|
263
|
-
name: 'fill_form',
|
|
264
|
-
description: `Fill out multiple form elements at once`,
|
|
265
|
-
annotations: {
|
|
266
|
-
category: ToolCategory.INPUT,
|
|
267
|
-
readOnlyHint: false,
|
|
268
|
-
},
|
|
269
|
-
schema: {
|
|
270
|
-
elements: zod
|
|
271
|
-
.array(zod.object({
|
|
272
|
-
uid: zod.string().describe('The uid of the element to fill out'),
|
|
273
|
-
value: zod.string().describe('Value for the element'),
|
|
274
|
-
}))
|
|
275
|
-
.describe('Elements from snapshot to fill out.'),
|
|
276
|
-
includeSnapshot: includeSnapshotSchema,
|
|
277
|
-
},
|
|
278
|
-
handler: async (request, response, context) => {
|
|
279
|
-
const page = request.page;
|
|
280
|
-
for (const element of request.params.elements) {
|
|
281
|
-
await context.waitForEventsAfterAction(async () => {
|
|
282
|
-
await fillFormElement(element.uid, element.value, context, page);
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
response.appendResponseLine(`Successfully filled out the form`);
|
|
286
|
-
if (request.params.includeSnapshot) {
|
|
287
|
-
response.includeSnapshot();
|
|
288
|
-
}
|
|
289
|
-
},
|
|
290
|
-
});
|
|
291
|
-
export const uploadFile = definePageTool({
|
|
292
|
-
name: 'upload_file',
|
|
293
|
-
description: 'Upload a file through a provided element.',
|
|
294
|
-
annotations: {
|
|
295
|
-
category: ToolCategory.INPUT,
|
|
296
|
-
readOnlyHint: false,
|
|
297
|
-
},
|
|
298
|
-
schema: {
|
|
299
|
-
uid: zod
|
|
300
|
-
.string()
|
|
301
|
-
.describe('The uid of the file input element or an element that will open file chooser on the page from the page content snapshot'),
|
|
302
|
-
filePath: zod.string().describe('The local path of the file to upload'),
|
|
303
|
-
includeSnapshot: includeSnapshotSchema,
|
|
304
|
-
},
|
|
305
|
-
handler: async (request, response) => {
|
|
306
|
-
const { uid, filePath } = request.params;
|
|
307
|
-
const handle = (await request.page.getElementByUid(uid));
|
|
308
|
-
try {
|
|
309
|
-
try {
|
|
310
|
-
await handle.uploadFile(filePath);
|
|
311
|
-
}
|
|
312
|
-
catch {
|
|
313
|
-
// Some sites use a proxy element to trigger file upload instead of
|
|
314
|
-
// a type=file element. In this case, we want to default to
|
|
315
|
-
// Page.waitForFileChooser() and upload the file this way.
|
|
316
|
-
try {
|
|
317
|
-
const [fileChooser] = await Promise.all([
|
|
318
|
-
request.page.pptrPage.waitForFileChooser({ timeout: 3000 }),
|
|
319
|
-
handle.asLocator().click(),
|
|
320
|
-
]);
|
|
321
|
-
await fileChooser.accept([filePath]);
|
|
322
|
-
}
|
|
323
|
-
catch {
|
|
324
|
-
throw new Error(`Failed to upload file. The element could not accept the file directly, and clicking it did not trigger a file chooser.`);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
if (request.params.includeSnapshot) {
|
|
328
|
-
response.includeSnapshot();
|
|
329
|
-
}
|
|
330
|
-
response.appendResponseLine(`File uploaded from ${filePath}.`);
|
|
331
|
-
}
|
|
332
|
-
finally {
|
|
333
|
-
void handle.dispose();
|
|
334
|
-
}
|
|
335
|
-
},
|
|
336
|
-
});
|
|
337
|
-
export const pressKey = definePageTool({
|
|
338
|
-
name: 'press_key',
|
|
339
|
-
description: `Press a key or key combination. Use this when other input methods like fill() cannot be used (e.g., keyboard shortcuts, navigation keys, or special key combinations).`,
|
|
340
|
-
annotations: {
|
|
341
|
-
category: ToolCategory.INPUT,
|
|
342
|
-
readOnlyHint: false,
|
|
343
|
-
},
|
|
344
|
-
schema: {
|
|
345
|
-
key: zod
|
|
346
|
-
.string()
|
|
347
|
-
.describe('A key or a combination (e.g., "Enter", "Control+A", "Control++", "Control+Shift+R"). Modifiers: Control, Shift, Alt, Meta'),
|
|
348
|
-
includeSnapshot: includeSnapshotSchema,
|
|
349
|
-
},
|
|
350
|
-
handler: async (request, response, context) => {
|
|
351
|
-
const page = request.page;
|
|
352
|
-
const tokens = parseKey(request.params.key);
|
|
353
|
-
const [key, ...modifiers] = tokens;
|
|
354
|
-
await context.waitForEventsAfterAction(async () => {
|
|
355
|
-
for (const modifier of modifiers) {
|
|
356
|
-
await page.pptrPage.keyboard.down(modifier);
|
|
357
|
-
}
|
|
358
|
-
await page.pptrPage.keyboard.press(key);
|
|
359
|
-
for (const modifier of modifiers.toReversed()) {
|
|
360
|
-
await page.pptrPage.keyboard.up(modifier);
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
response.appendResponseLine(`Successfully pressed key: ${request.params.key}`);
|
|
364
|
-
if (request.params.includeSnapshot) {
|
|
365
|
-
response.includeSnapshot();
|
|
366
|
-
}
|
|
367
|
-
},
|
|
368
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
import { snapshot, navigation, generateReport, zod, } from '../third_party/index.js';
|
|
8
|
-
import { ToolCategory } from './categories.js';
|
|
9
|
-
import { startTrace } from './performance.js';
|
|
10
|
-
import { definePageTool } from './ToolDefinition.js';
|
|
11
|
-
export const lighthouseAudit = definePageTool({
|
|
12
|
-
name: 'lighthouse_audit',
|
|
13
|
-
description: `Get Lighthouse score and reports for accessibility, SEO and best practices. This excludes performance. For performance audits, run ${startTrace.name}`,
|
|
14
|
-
annotations: {
|
|
15
|
-
category: ToolCategory.DEBUGGING,
|
|
16
|
-
readOnlyHint: true,
|
|
17
|
-
},
|
|
18
|
-
schema: {
|
|
19
|
-
mode: zod
|
|
20
|
-
.enum(['navigation', 'snapshot'])
|
|
21
|
-
.default('navigation')
|
|
22
|
-
.describe('"navigation" reloads & audits. "snapshot" analyzes current state.'),
|
|
23
|
-
device: zod
|
|
24
|
-
.enum(['desktop', 'mobile'])
|
|
25
|
-
.default('desktop')
|
|
26
|
-
.describe('Device to emulate.'),
|
|
27
|
-
outputDirPath: zod
|
|
28
|
-
.string()
|
|
29
|
-
.optional()
|
|
30
|
-
.describe('Directory for reports. If omitted, uses temporary files.'),
|
|
31
|
-
},
|
|
32
|
-
handler: async (request, response, context) => {
|
|
33
|
-
const page = request.page;
|
|
34
|
-
const categories = ['accessibility', 'seo', 'best-practices'];
|
|
35
|
-
const formats = ['json', 'html'];
|
|
36
|
-
const { mode = 'navigation', device = 'desktop', outputDirPath, } = request.params;
|
|
37
|
-
const flags = {
|
|
38
|
-
onlyCategories: categories,
|
|
39
|
-
output: formats,
|
|
40
|
-
// Default 30 second timeout for page load.
|
|
41
|
-
maxWaitForLoad: 30_000,
|
|
42
|
-
};
|
|
43
|
-
if (device === 'desktop') {
|
|
44
|
-
flags.formFactor = 'desktop';
|
|
45
|
-
flags.screenEmulation = {
|
|
46
|
-
mobile: false,
|
|
47
|
-
width: 1350,
|
|
48
|
-
height: 940,
|
|
49
|
-
deviceScaleFactor: 1,
|
|
50
|
-
disabled: false,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
flags.formFactor = 'mobile';
|
|
55
|
-
flags.screenEmulation = {
|
|
56
|
-
mobile: true,
|
|
57
|
-
width: 412,
|
|
58
|
-
height: 823,
|
|
59
|
-
deviceScaleFactor: 1.75,
|
|
60
|
-
disabled: false,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
let result;
|
|
64
|
-
try {
|
|
65
|
-
if (mode === 'navigation') {
|
|
66
|
-
result = await navigation(page.pptrPage, page.pptrPage.url(), {
|
|
67
|
-
flags,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
result = await snapshot(page.pptrPage, {
|
|
72
|
-
flags,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
if (!result) {
|
|
76
|
-
throw new Error('Lighthouse audit failed.');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
finally {
|
|
80
|
-
await context.restoreEmulation(page);
|
|
81
|
-
}
|
|
82
|
-
const lhr = result.lhr;
|
|
83
|
-
const reportPaths = [];
|
|
84
|
-
const encoder = new TextEncoder();
|
|
85
|
-
for (const format of formats) {
|
|
86
|
-
const report = generateReport(lhr, format);
|
|
87
|
-
const data = encoder.encode(report);
|
|
88
|
-
if (outputDirPath) {
|
|
89
|
-
const reportPath = path.join(outputDirPath, `report.${format}`);
|
|
90
|
-
const { filename } = await context.saveFile(data, reportPath);
|
|
91
|
-
reportPaths.push(filename);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
const { filepath } = await context.saveTemporaryFile(data, `report.${format}`);
|
|
95
|
-
reportPaths.push(filepath);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const categoryScores = Object.values(lhr.categories).map(c => ({
|
|
99
|
-
id: c.id,
|
|
100
|
-
title: c.title,
|
|
101
|
-
score: c.score,
|
|
102
|
-
}));
|
|
103
|
-
const failedAudits = Object.values(lhr.audits).filter(a => a.score !== null && a.score < 1).length;
|
|
104
|
-
const passedAudits = Object.values(lhr.audits).filter(a => a.score === 1).length;
|
|
105
|
-
const output = {
|
|
106
|
-
summary: {
|
|
107
|
-
mode,
|
|
108
|
-
device,
|
|
109
|
-
url: lhr.mainDocumentUrl,
|
|
110
|
-
scores: categoryScores,
|
|
111
|
-
audits: {
|
|
112
|
-
failed: failedAudits,
|
|
113
|
-
passed: passedAudits,
|
|
114
|
-
},
|
|
115
|
-
timing: {
|
|
116
|
-
total: lhr.timing.total,
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
reports: reportPaths,
|
|
120
|
-
};
|
|
121
|
-
response.attachLighthouseResult(output);
|
|
122
|
-
},
|
|
123
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
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';
|
|
8
|
-
import { definePageTool } from './ToolDefinition.js';
|
|
9
|
-
export const takeMemorySnapshot = definePageTool({
|
|
10
|
-
name: 'take_memory_snapshot',
|
|
11
|
-
description: `Capture a memory heapsnapshot of the currently selected page to memory leak debugging`,
|
|
12
|
-
annotations: {
|
|
13
|
-
category: ToolCategory.PERFORMANCE,
|
|
14
|
-
readOnlyHint: true,
|
|
15
|
-
},
|
|
16
|
-
schema: {
|
|
17
|
-
filePath: zod
|
|
18
|
-
.string()
|
|
19
|
-
.describe('A path to a .heapsnapshot file to save the heapsnapshot to.'),
|
|
20
|
-
},
|
|
21
|
-
handler: async (request, response, _context) => {
|
|
22
|
-
const page = request.page;
|
|
23
|
-
await page.pptrPage.captureHeapSnapshot({
|
|
24
|
-
path: request.params.filePath,
|
|
25
|
-
});
|
|
26
|
-
response.appendResponseLine(`Heap snapshot saved to ${request.params.filePath}`);
|
|
27
|
-
},
|
|
28
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
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';
|
|
8
|
-
import { definePageTool } from './ToolDefinition.js';
|
|
9
|
-
const FILTERABLE_RESOURCE_TYPES = [
|
|
10
|
-
'document',
|
|
11
|
-
'stylesheet',
|
|
12
|
-
'image',
|
|
13
|
-
'media',
|
|
14
|
-
'font',
|
|
15
|
-
'script',
|
|
16
|
-
'texttrack',
|
|
17
|
-
'xhr',
|
|
18
|
-
'fetch',
|
|
19
|
-
'prefetch',
|
|
20
|
-
'eventsource',
|
|
21
|
-
'websocket',
|
|
22
|
-
'manifest',
|
|
23
|
-
'signedexchange',
|
|
24
|
-
'ping',
|
|
25
|
-
'cspviolationreport',
|
|
26
|
-
'preflight',
|
|
27
|
-
'fedcm',
|
|
28
|
-
'other',
|
|
29
|
-
];
|
|
30
|
-
export const listNetworkRequests = definePageTool({
|
|
31
|
-
name: 'list_network_requests',
|
|
32
|
-
description: `List all requests for the currently selected page since the last navigation.`,
|
|
33
|
-
annotations: {
|
|
34
|
-
category: ToolCategory.NETWORK,
|
|
35
|
-
readOnlyHint: true,
|
|
36
|
-
},
|
|
37
|
-
schema: {
|
|
38
|
-
pageSize: zod
|
|
39
|
-
.number()
|
|
40
|
-
.int()
|
|
41
|
-
.positive()
|
|
42
|
-
.optional()
|
|
43
|
-
.describe('Maximum number of requests 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
|
-
resourceTypes: zod
|
|
51
|
-
.array(zod.enum(FILTERABLE_RESOURCE_TYPES))
|
|
52
|
-
.optional()
|
|
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.'),
|
|
59
|
-
},
|
|
60
|
-
handler: async (request, response, context) => {
|
|
61
|
-
const data = await context.getDevToolsData(request.page);
|
|
62
|
-
response.attachDevToolsData(data);
|
|
63
|
-
const reqid = data?.cdpRequestId
|
|
64
|
-
? context.resolveCdpRequestId(request.page, data.cdpRequestId)
|
|
65
|
-
: undefined;
|
|
66
|
-
response.setIncludeNetworkRequests(true, {
|
|
67
|
-
pageSize: request.params.pageSize,
|
|
68
|
-
pageIdx: request.params.pageIdx,
|
|
69
|
-
resourceTypes: request.params.resourceTypes,
|
|
70
|
-
includePreservedRequests: request.params.includePreservedRequests,
|
|
71
|
-
networkRequestIdInDevToolsUI: reqid,
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
export const getNetworkRequest = definePageTool({
|
|
76
|
-
name: 'get_network_request',
|
|
77
|
-
description: `Gets a network request by an optional reqid, if omitted returns the currently selected request in the DevTools Network panel.`,
|
|
78
|
-
annotations: {
|
|
79
|
-
category: ToolCategory.NETWORK,
|
|
80
|
-
readOnlyHint: false,
|
|
81
|
-
},
|
|
82
|
-
schema: {
|
|
83
|
-
reqid: zod
|
|
84
|
-
.number()
|
|
85
|
-
.optional()
|
|
86
|
-
.describe('The reqid of the network request. If omitted returns the currently selected request in the DevTools Network panel.'),
|
|
87
|
-
requestFilePath: zod
|
|
88
|
-
.string()
|
|
89
|
-
.optional()
|
|
90
|
-
.describe('The absolute or relative path to save the request body to. If omitted, the body is returned inline.'),
|
|
91
|
-
responseFilePath: zod
|
|
92
|
-
.string()
|
|
93
|
-
.optional()
|
|
94
|
-
.describe('The absolute or relative path to save the response body to. If omitted, the body is returned inline.'),
|
|
95
|
-
},
|
|
96
|
-
handler: async (request, response, context) => {
|
|
97
|
-
if (request.params.reqid) {
|
|
98
|
-
response.attachNetworkRequest(request.params.reqid, {
|
|
99
|
-
requestFilePath: request.params.requestFilePath,
|
|
100
|
-
responseFilePath: request.params.responseFilePath,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
const data = await context.getDevToolsData(request.page);
|
|
105
|
-
response.attachDevToolsData(data);
|
|
106
|
-
const reqid = data?.cdpRequestId
|
|
107
|
-
? context.resolveCdpRequestId(request.page, data.cdpRequestId)
|
|
108
|
-
: undefined;
|
|
109
|
-
if (reqid) {
|
|
110
|
-
response.attachNetworkRequest(reqid, {
|
|
111
|
-
requestFilePath: request.params.requestFilePath,
|
|
112
|
-
responseFilePath: request.params.responseFilePath,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
response.appendResponseLine(`Nothing is currently selected in the DevTools Network panel.`);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
});
|