chrome-devtools-mcp 1.10.1 → 1.12.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 +72 -20
- package/build/src/BrowserManager.js +155 -27
- package/build/src/McpContext.js +598 -200
- package/build/src/McpPage.js +513 -131
- package/build/src/McpResponse.js +291 -116
- package/build/src/McpWorker.js +66 -0
- package/build/src/SlimMcpResponse.js +5 -1
- package/build/src/TextSnapshot.js +40 -20
- package/build/src/ToolHandler.js +306 -147
- package/build/src/bin/chrome-devtools-mcp-main.js +13 -10
- package/build/src/bin/chrome-devtools-mcp.js +1 -1
- package/build/src/bin/chrome-devtools.js +34 -44
- package/build/src/collectors/PageCollector.js +13 -9
- package/build/src/collectors/ServiceWorkerCollector.js +20 -13
- package/build/src/collectors/constants.js +7 -0
- package/build/src/config/ConfigLocator.js +70 -0
- package/build/src/config/ConfigParser.js +159 -0
- package/build/src/config/ConfigWatcher.js +94 -0
- package/build/src/config/ServerConfig.js +251 -0
- package/build/src/config/browser-options.js +15 -17
- package/build/src/config/category-options.js +15 -30
- package/build/src/config/cli-commands.js +165 -5
- package/build/src/config/cli-options.js +441 -58
- package/build/src/config/mcp-options.js +212 -264
- package/build/src/config/puppeteer-options.js +67 -0
- package/build/src/config/tool-options.js +60 -0
- package/build/src/daemon/client.js +84 -44
- package/build/src/daemon/daemon.js +59 -45
- package/build/src/daemon/utils.js +46 -12
- package/build/src/devtools/DevToolsCommentBridge.js +71 -11
- package/build/src/devtools/DevtoolsUtils.js +52 -15
- package/build/src/devtools/McpHostBindingAdapter.js +0 -1
- package/build/src/formatters/CommentFormatter.js +4 -13
- package/build/src/formatters/ConsoleFormatter.js +29 -2
- package/build/src/formatters/CssFormatter.js +3 -2
- package/build/src/formatters/HeapSnapshotFormatter.js +111 -57
- package/build/src/formatters/IssueFormatter.js +33 -32
- package/build/src/formatters/NetworkFormatter.js +62 -22
- package/build/src/formatters/RemoteObjectFormatter.js +231 -0
- package/build/src/formatters/SnapshotFormatter.js +44 -7
- package/build/src/index.js +285 -88
- package/build/src/processors/ChunkedTraceParser.js +11 -11
- package/build/src/processors/HeapSnapshotManager.js +455 -156
- package/build/src/processors/PerformanceTrace.js +9 -9
- package/build/src/telemetry/ClearcutLogger.js +1 -1
- package/build/src/telemetry/transformation.js +7 -11
- package/build/src/telemetry/watchdog/main.js +1 -1
- package/build/src/third_party/THIRD_PARTY_NOTICES +399 -689
- package/build/src/third_party/bundled-packages.json +7 -8
- package/build/src/third_party/cli.js +9239 -0
- package/build/src/third_party/devtools-formatter-worker.js +4299 -2517
- package/build/src/third_party/devtools-heap-snapshot-worker.js +1298 -22
- package/build/src/third_party/index.js +132003 -146852
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantRead.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantReadOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSet.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSetOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/deprecation.md +1 -1
- package/build/src/third_party/issue-descriptions/genericGeolocationPromptWithoutUserGesture.md +5 -0
- package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +2 -0
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
- package/build/src/tools/ToolDefinition.js +102 -12
- package/build/src/tools/comments.js +62 -4
- package/build/src/tools/console.js +6 -4
- package/build/src/tools/css.js +5 -2
- package/build/src/tools/emulation.js +22 -8
- package/build/src/tools/extensions.js +5 -0
- package/build/src/tools/input.js +29 -9
- package/build/src/tools/lighthouse.js +136 -12
- package/build/src/tools/memory.js +166 -59
- package/build/src/tools/network.js +5 -4
- package/build/src/tools/pages.js +52 -7
- package/build/src/tools/performance.js +28 -7
- package/build/src/tools/pwa.js +7 -0
- package/build/src/tools/screencast.js +74 -33
- package/build/src/tools/screenshot.js +52 -21
- package/build/src/tools/script.js +125 -40
- package/build/src/tools/slim/tools.js +27 -13
- package/build/src/tools/snapshot.js +13 -3
- package/build/src/tools/thirdPartyDeveloper.js +9 -5
- package/build/src/tools/tools.js +35 -22
- package/build/src/tools/webmcp.js +11 -6
- package/build/src/types.js +11 -0
- package/build/src/utils/TaskRunner.js +136 -0
- package/build/src/utils/WaitForHelper.js +15 -2
- package/build/src/utils/bytes.js +2 -12
- package/build/src/utils/check-for-updates.js +2 -2
- package/build/src/utils/disclaimers.js +27 -0
- package/build/src/utils/errorHandling.js +20 -0
- package/build/src/utils/keyboard.js +14 -2
- package/build/src/utils/logger.js +84 -5
- package/build/src/utils/resourceType.js +27 -0
- package/build/src/utils/text.js +44 -0
- package/build/src/utils/timeout.js +14 -0
- package/build/src/utils/url.js +140 -3
- package/build/src/version.js +1 -1
- package/package.json +16 -11
- package/skills/a11y-debugging/SKILL.md +7 -12
- package/skills/chrome-devtools/SKILL.md +2 -2
- package/skills/chrome-devtools-cli/SKILL.md +18 -15
- package/skills/cookie-debugging/SKILL.md +8 -5
- package/skills/debug-optimize-lcp/SKILL.md +1 -1
- package/skills/troubleshooting/SKILL.md +5 -6
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import path from 'node:path';
|
|
7
|
-
import {
|
|
7
|
+
import { generateReport, zod, } from '../third_party/index.js';
|
|
8
8
|
import { ToolCategory } from './categories.js';
|
|
9
9
|
import { startTrace } from './performance.js';
|
|
10
|
-
import { definePageTool } from './ToolDefinition.js';
|
|
10
|
+
import { definePageTool, } from './ToolDefinition.js';
|
|
11
11
|
// Kept in sync with `constants.userAgents` in Lighthouse's
|
|
12
12
|
// core/config/constants.js, which `lighthouse:default` and the `desktop`
|
|
13
13
|
// preset use. The bundle in src/third_party only re-exports the runner
|
|
@@ -15,9 +15,122 @@ import { definePageTool } from './ToolDefinition.js';
|
|
|
15
15
|
// screen emulation metrics below. Refresh via scripts/update-lighthouse.ts.
|
|
16
16
|
const MOBILE_USER_AGENT = 'Mozilla/5.0 (Linux; Android 11; moto g power (2022)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Mobile Safari/537.36';
|
|
17
17
|
const DESKTOP_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36';
|
|
18
|
+
// Caps the number of DOM nodes returned inline per failing audit to keep the
|
|
19
|
+
// response compact. The full list remains available in the saved reports.
|
|
20
|
+
const MAX_NODES_PER_AUDIT = 10;
|
|
21
|
+
const isRecord = (value) => {
|
|
22
|
+
return typeof value === 'object' && value !== null;
|
|
23
|
+
};
|
|
24
|
+
// Lighthouse's navigation mode only accepts the URL schemes in
|
|
25
|
+
// `allowedProtocols` (core/lib/url-utils.js) and throws a bare `INVALID_URL`
|
|
26
|
+
// for anything else, such as file:// or about:blank.
|
|
27
|
+
const isInvalidUrlError = (error) => {
|
|
28
|
+
return isRecord(error) && error.code === 'INVALID_URL';
|
|
29
|
+
};
|
|
30
|
+
const getString = (value) => {
|
|
31
|
+
return typeof value === 'string' ? value : undefined;
|
|
32
|
+
};
|
|
33
|
+
const toAuditNode = (value) => {
|
|
34
|
+
const node = {};
|
|
35
|
+
const selector = getString(value.selector);
|
|
36
|
+
const snippet = getString(value.snippet);
|
|
37
|
+
const nodeLabel = getString(value.nodeLabel);
|
|
38
|
+
const explanation = getString(value.explanation);
|
|
39
|
+
if (selector) {
|
|
40
|
+
node.selector = selector;
|
|
41
|
+
}
|
|
42
|
+
if (snippet) {
|
|
43
|
+
node.snippet = snippet;
|
|
44
|
+
}
|
|
45
|
+
if (nodeLabel) {
|
|
46
|
+
node.nodeLabel = nodeLabel;
|
|
47
|
+
}
|
|
48
|
+
if (explanation) {
|
|
49
|
+
node.explanation = explanation;
|
|
50
|
+
}
|
|
51
|
+
return node;
|
|
52
|
+
};
|
|
53
|
+
const getNodeKey = (value, nodes) => {
|
|
54
|
+
const id = getString(value.lhId) ?? getString(value.path);
|
|
55
|
+
if (id) {
|
|
56
|
+
return `id:${id}`;
|
|
57
|
+
}
|
|
58
|
+
const selector = getString(value.selector);
|
|
59
|
+
const snippet = getString(value.snippet);
|
|
60
|
+
if (selector || snippet) {
|
|
61
|
+
return `selector:${selector ?? ''}|${snippet ?? ''}`;
|
|
62
|
+
}
|
|
63
|
+
// Nodes without any identifying fields cannot be deduplicated reliably, so
|
|
64
|
+
// each one gets a unique key.
|
|
65
|
+
return `unidentified:${nodes.size}`;
|
|
66
|
+
};
|
|
67
|
+
// Recursively collects node values from audit details. Walking the details
|
|
68
|
+
// generically covers tables and lists of tables alike. Sub-items are skipped:
|
|
69
|
+
// for axe audits they hold related context (e.g. the background element for
|
|
70
|
+
// `color-contrast`) rather than failing elements.
|
|
71
|
+
const collectNodes = (value, nodes) => {
|
|
72
|
+
if (Array.isArray(value)) {
|
|
73
|
+
for (const item of value) {
|
|
74
|
+
collectNodes(item, nodes);
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (!isRecord(value) ||
|
|
79
|
+
value.type === 'debugdata' ||
|
|
80
|
+
value.type === 'subitems') {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (value.type === 'node') {
|
|
84
|
+
const key = getNodeKey(value, nodes);
|
|
85
|
+
// Merge duplicates so that fields such as `explanation` are kept
|
|
86
|
+
// regardless of which occurrence carries them.
|
|
87
|
+
nodes.set(key, { ...toAuditNode(value), ...nodes.get(key) });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
for (const [name, child] of Object.entries(value)) {
|
|
91
|
+
if (name === 'subItems') {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
collectNodes(child, nodes);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const getFailedAudits = (lhr) => {
|
|
98
|
+
const categoriesByAudit = new Map();
|
|
99
|
+
for (const category of Object.values(lhr.categories)) {
|
|
100
|
+
for (const ref of category.auditRefs) {
|
|
101
|
+
const categoryIds = categoriesByAudit.get(ref.id) ?? [];
|
|
102
|
+
categoryIds.push(category.id);
|
|
103
|
+
categoriesByAudit.set(ref.id, categoryIds);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const failedAudits = [];
|
|
107
|
+
for (const audit of Object.values(lhr.audits)) {
|
|
108
|
+
if (audit.score === null || audit.score >= 1) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const nodes = new Map();
|
|
112
|
+
collectNodes(audit.details, nodes);
|
|
113
|
+
const failedAudit = {
|
|
114
|
+
id: audit.id,
|
|
115
|
+
title: audit.title,
|
|
116
|
+
score: audit.score,
|
|
117
|
+
categories: categoriesByAudit.get(audit.id) ?? [],
|
|
118
|
+
nodes: [...nodes.values()].slice(0, MAX_NODES_PER_AUDIT),
|
|
119
|
+
totalNodes: nodes.size,
|
|
120
|
+
};
|
|
121
|
+
if (audit.description) {
|
|
122
|
+
failedAudit.description = audit.description;
|
|
123
|
+
}
|
|
124
|
+
if (audit.displayValue) {
|
|
125
|
+
failedAudit.displayValue = audit.displayValue;
|
|
126
|
+
}
|
|
127
|
+
failedAudits.push(failedAudit);
|
|
128
|
+
}
|
|
129
|
+
return failedAudits;
|
|
130
|
+
};
|
|
18
131
|
export const lighthouseAudit = definePageTool((args) => ({
|
|
19
132
|
name: 'lighthouse_audit',
|
|
20
|
-
description: `Get Lighthouse
|
|
133
|
+
description: `Get Lighthouse scores, failing audits, and the DOM nodes they flag for accessibility, SEO, best practices, and agentic browsing. Full reports are saved to disk. This excludes performance. For performance audits, run ${startTrace(args).name}`,
|
|
21
134
|
annotations: {
|
|
22
135
|
category: ToolCategory.DEBUGGING,
|
|
23
136
|
readOnlyHint: false,
|
|
@@ -37,6 +150,7 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
37
150
|
.describe('Directory for reports. If omitted, uses temporary files.'),
|
|
38
151
|
},
|
|
39
152
|
blockedByDialog: true,
|
|
153
|
+
concurrency: 'exclusive',
|
|
40
154
|
verifyFilesSchema: {
|
|
41
155
|
outputDirPath: true,
|
|
42
156
|
},
|
|
@@ -81,14 +195,19 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
81
195
|
let result;
|
|
82
196
|
try {
|
|
83
197
|
if (mode === 'navigation') {
|
|
84
|
-
|
|
85
|
-
flags
|
|
86
|
-
}
|
|
198
|
+
try {
|
|
199
|
+
result = await page.lighthouseNavigation(flags);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (isInvalidUrlError(error)) {
|
|
203
|
+
const url = page.pptrPage.url();
|
|
204
|
+
throw new Error(`Lighthouse "navigation" mode cannot audit ${url}: it only supports http:, https:, chrome: and chrome-extension: URLs. Use mode "snapshot" to audit the page in its current state.`, { cause: error });
|
|
205
|
+
}
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
87
208
|
}
|
|
88
209
|
else {
|
|
89
|
-
result = await
|
|
90
|
-
flags,
|
|
91
|
-
});
|
|
210
|
+
result = await page.lighthouseSnapshot(flags);
|
|
92
211
|
}
|
|
93
212
|
if (!result) {
|
|
94
213
|
throw new Error('Lighthouse audit failed.');
|
|
@@ -101,7 +220,7 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
101
220
|
const reportPaths = [];
|
|
102
221
|
const encoder = new TextEncoder();
|
|
103
222
|
const savePromises = formats.map(async (format) => {
|
|
104
|
-
const report = generateReport(lhr, format);
|
|
223
|
+
const report = await generateReport(lhr, format);
|
|
105
224
|
const data = encoder.encode(report);
|
|
106
225
|
if (outputDirPath) {
|
|
107
226
|
const reportPath = path.join(outputDirPath, `report`);
|
|
@@ -118,12 +237,16 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
118
237
|
}
|
|
119
238
|
reportPaths.push(res.value);
|
|
120
239
|
}
|
|
240
|
+
// Lighthouse sets runtimeError when it could not load the page; the categories are unscored.
|
|
241
|
+
if (lhr.runtimeError) {
|
|
242
|
+
throw new Error(`Lighthouse could not audit the page (${lhr.runtimeError.code}): ${lhr.runtimeError.message} Reports: ${reportPaths.join(', ')}`);
|
|
243
|
+
}
|
|
121
244
|
const categoryScores = Object.values(lhr.categories).map(c => ({
|
|
122
245
|
id: c.id,
|
|
123
246
|
title: c.title,
|
|
124
247
|
score: c.score,
|
|
125
248
|
}));
|
|
126
|
-
const failedAudits =
|
|
249
|
+
const failedAudits = getFailedAudits(lhr);
|
|
127
250
|
const passedAudits = Object.values(lhr.audits).filter(a => a.score === 1).length;
|
|
128
251
|
const output = {
|
|
129
252
|
summary: {
|
|
@@ -134,13 +257,14 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
134
257
|
url: lhr.finalDisplayedUrl,
|
|
135
258
|
scores: categoryScores,
|
|
136
259
|
audits: {
|
|
137
|
-
failed: failedAudits,
|
|
260
|
+
failed: failedAudits.length,
|
|
138
261
|
passed: passedAudits,
|
|
139
262
|
},
|
|
140
263
|
timing: {
|
|
141
264
|
total: lhr.timing.total,
|
|
142
265
|
},
|
|
143
266
|
},
|
|
267
|
+
failedAudits,
|
|
144
268
|
reports: reportPaths,
|
|
145
269
|
};
|
|
146
270
|
response.attachLighthouseResult(output);
|