chrome-devtools-mcp 1.10.0 → 1.11.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/build/src/BrowserManager.js +132 -13
- package/build/src/McpContext.js +188 -138
- package/build/src/McpPage.js +348 -96
- package/build/src/McpResponse.js +234 -76
- package/build/src/McpWorker.js +66 -0
- package/build/src/SlimMcpResponse.js +5 -1
- package/build/src/TextSnapshot.js +3 -2
- package/build/src/ToolHandler.js +80 -42
- package/build/src/bin/chrome-devtools-mcp-main.js +8 -7
- package/build/src/bin/chrome-devtools-mcp.js +1 -1
- package/build/src/bin/chrome-devtools.js +31 -41
- package/build/src/collectors/ServiceWorkerCollector.js +18 -11
- package/build/src/config/ConfigLocator.js +70 -0
- package/build/src/config/ConfigParser.js +264 -0
- package/build/src/config/ConfigWatcher.js +93 -0
- package/build/src/config/browser-options.js +2 -13
- 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 +410 -43
- package/build/src/config/mcp-options.js +156 -234
- package/build/src/config/puppeteer-options.js +65 -0
- package/build/src/config/tool-options.js +60 -0
- package/build/src/daemon/client.js +81 -41
- package/build/src/daemon/daemon.js +55 -45
- package/build/src/daemon/utils.js +44 -11
- package/build/src/devtools/DevToolsCommentBridge.js +43 -6
- package/build/src/devtools/DevtoolsUtils.js +3 -3
- package/build/src/devtools/McpHostBindingAdapter.js +0 -1
- package/build/src/formatters/CommentFormatter.js +4 -13
- package/build/src/formatters/ConsoleFormatter.js +1 -1
- package/build/src/formatters/CssFormatter.js +3 -2
- package/build/src/formatters/HeapSnapshotFormatter.js +104 -46
- package/build/src/formatters/IssueFormatter.js +33 -32
- package/build/src/formatters/NetworkFormatter.js +12 -11
- package/build/src/formatters/SnapshotFormatter.js +31 -4
- package/build/src/index.js +54 -9
- package/build/src/processors/ChunkedTraceParser.js +11 -11
- package/build/src/processors/HeapSnapshotManager.js +121 -84
- 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 +10 -367
- package/build/src/third_party/bundled-packages.json +7 -8
- package/build/src/third_party/devtools-formatter-worker.js +1193 -62
- package/build/src/third_party/devtools-heap-snapshot-worker.js +1126 -21
- package/build/src/third_party/index.js +8087 -19416
- 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 +3 -3
- package/build/src/tools/ToolDefinition.js +16 -4
- package/build/src/tools/comments.js +20 -1
- package/build/src/tools/css.js +4 -2
- package/build/src/tools/emulation.js +17 -4
- package/build/src/tools/input.js +8 -3
- package/build/src/tools/lighthouse.js +112 -4
- package/build/src/tools/memory.js +129 -28
- package/build/src/tools/pages.js +5 -2
- package/build/src/tools/performance.js +21 -3
- package/build/src/tools/screencast.js +71 -32
- package/build/src/tools/screenshot.js +29 -14
- package/build/src/tools/script.js +90 -37
- package/build/src/tools/slim/tools.js +6 -8
- package/build/src/tools/thirdPartyDeveloper.js +6 -4
- package/build/src/tools/tools.js +35 -22
- package/build/src/tools/webmcp.js +9 -6
- package/build/src/types.js +11 -0
- package/build/src/utils/WaitForHelper.js +14 -1
- package/build/src/utils/check-for-updates.js +1 -1
- package/build/src/utils/errorHandling.js +20 -0
- package/build/src/utils/logger.js +15 -5
- package/build/src/utils/text.js +15 -0
- package/build/src/utils/url.js +99 -3
- package/build/src/version.js +1 -1
- package/package.json +14 -10
- package/skills/a11y-debugging/SKILL.md +4 -4
- 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
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
# Third-party websites are allowed to read cookies on this page
|
|
2
2
|
|
|
3
3
|
One or more websites are allowed to bypass user settings to read third-party cookies on this page. Web developers should take steps to remove these reads without disrupting user experience. To forcefully block these third-party cookies, update [user settings](manageCookiesHelpPage).
|
|
4
|
-
{PLACEHOLDER_topleveloptout}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Third-party websites are allowed to read cookies on this page
|
|
2
|
+
|
|
3
|
+
One or more websites are allowed to bypass user settings to read third-party cookies on this page. Web developers should take steps to remove these reads without disrupting user experience. To forcefully block these third-party cookies, update [user settings](manageCookiesHelpPage).
|
|
4
|
+
|
|
5
|
+
(Top level site opt-out: {PLACEHOLDER_optOutPercentage}% - [learn more](gracePeriodStagedControlExplainer))
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
# Third-party websites are allowed to set cookies on this page
|
|
2
2
|
|
|
3
3
|
One or more websites are allowed to bypass user settings to set third-party cookies on this page. Web developers should take steps to remove these sets without disrupting user experience. To forcefully block these third-party cookies, update [user settings](manageCookiesHelpPage).
|
|
4
|
-
{PLACEHOLDER_topleveloptout}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Third-party websites are allowed to set cookies on this page
|
|
2
|
+
|
|
3
|
+
One or more websites are allowed to bypass user settings to set third-party cookies on this page. Web developers should take steps to remove these sets without disrupting user experience. To forcefully block these third-party cookies, update [user settings](manageCookiesHelpPage).
|
|
4
|
+
|
|
5
|
+
(Top level site opt-out: {PLACEHOLDER_optOutPercentage}% - [learn more](gracePeriodStagedControlExplainer))
|
package/build/src/third_party/issue-descriptions/genericGeolocationPromptWithoutUserGesture.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Geolocation permission prompts should not be shown without a user gesture
|
|
2
|
+
|
|
3
|
+
A geolocation permission prompt was triggered without a user gesture. Geolocation permission prompts triggered without a user gesture are often perceived as annoying by users and are less likely to be accepted.
|
|
4
|
+
|
|
5
|
+
Trigger a geolocation permission prompt only in response to a user gesture (for example, after the user clicks on a button) and provide context on why the permission is required.
|
|
@@ -31947,7 +31947,7 @@ var require_cjs = __commonJS({
|
|
|
31947
31947
|
let vLastCode = -1;
|
|
31948
31948
|
if (validate && start < end) {
|
|
31949
31949
|
const c0 = url.charCodeAt(start);
|
|
31950
|
-
if (!(isValidHostnameChar(c0) || c0 === 46 || c0 === 95) || c0 === 45) {
|
|
31950
|
+
if (! /*@__INLINE__*/(isValidHostnameChar(c0) || c0 === 46 || c0 === 95) || c0 === 45) {
|
|
31951
31951
|
vValid = false;
|
|
31952
31952
|
}
|
|
31953
31953
|
}
|
|
@@ -31995,7 +31995,7 @@ var require_cjs = __commonJS({
|
|
|
31995
31995
|
else if (code >= 65 && code <= 90) {
|
|
31996
31996
|
hasUpper = true;
|
|
31997
31997
|
}
|
|
31998
|
-
else if (validate && !isValidHostnameChar(code)) {
|
|
31998
|
+
else if (validate && ! /*@__INLINE__*/isValidHostnameChar(code)) {
|
|
31999
31999
|
vValid = false;
|
|
32000
32000
|
}
|
|
32001
32001
|
if (validate) {
|
|
@@ -32169,7 +32169,7 @@ var require_cjs = __commonJS({
|
|
|
32169
32169
|
}
|
|
32170
32170
|
else if (
|
|
32171
32171
|
// A forbidden character in the label...
|
|
32172
|
-
!(isValidAscii(code) || code === 45 || code === 95) || // ...or a '-' starting a label (the byte right after a '.'). A label must
|
|
32172
|
+
! /*@__INLINE__*/(isValidAscii(code) || code === 45 || code === 95) || // ...or a '-' starting a label (the byte right after a '.'). A label must
|
|
32173
32173
|
// not begin with a hyphen (RFC 1034 §3.5 / RFC 1035 §2.3.1 LDH, as amended
|
|
32174
32174
|
// by RFC 1123 §2.1; cf. UTS #46 CheckHyphens). The first label is covered by
|
|
32175
32175
|
// the leading-character guard above; mirrors the trailing-'-' rule below.
|
|
@@ -13,7 +13,7 @@ export function definePageTool(definition) {
|
|
|
13
13
|
return {
|
|
14
14
|
...tool,
|
|
15
15
|
schema: {
|
|
16
|
-
...(args.pageIdRouting && !
|
|
16
|
+
...(args.pageIdRouting && !isSlimTool(tool) ? pageIdSchema : {}),
|
|
17
17
|
...tool.schema,
|
|
18
18
|
},
|
|
19
19
|
pageScoped: true,
|
|
@@ -56,9 +56,9 @@ export function viewportTransform(arg) {
|
|
|
56
56
|
width,
|
|
57
57
|
height,
|
|
58
58
|
deviceScaleFactor: dpr,
|
|
59
|
-
isMobile
|
|
60
|
-
isLandscape
|
|
61
|
-
hasTouch
|
|
59
|
+
isMobile,
|
|
60
|
+
isLandscape,
|
|
61
|
+
hasTouch,
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
export function geolocationTransform(arg) {
|
|
@@ -77,4 +77,16 @@ export function geolocationTransform(arg) {
|
|
|
77
77
|
longitude,
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
+
export function isSlimTool(tool) {
|
|
81
|
+
return Boolean(tool.annotations.conditions?.includes('slim'));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Slim mode replaces the regular tools with the slim tools. Only the tools of
|
|
85
|
+
* the current mode are registered, so a slim tool may share its name with a
|
|
86
|
+
* regular tool. `--slim` requires a restart, so the mode never changes while
|
|
87
|
+
* the server is running.
|
|
88
|
+
*/
|
|
89
|
+
export function isAvailableInMode(tool, serverArgs) {
|
|
90
|
+
return isSlimTool(tool) === Boolean(serverArgs.slim);
|
|
91
|
+
}
|
|
80
92
|
//# sourceMappingURL=ToolDefinition.js.map
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { zod } from '../third_party/index.js';
|
|
7
7
|
import { ToolCategory } from './categories.js';
|
|
8
8
|
import { definePageTool } from './ToolDefinition.js';
|
|
9
|
+
const DEVTOOLS_COMMENTS_UNAVAILABLE_MESSAGE = 'DevTools comments are not working right now. Possible reasons: the connected Chrome version does not support DevTools comments, the feature is disabled, or the DevTools window has not finished loading. Try again later, or continue without DevTools comments.';
|
|
9
10
|
export const openDevtools = definePageTool(() => ({
|
|
10
11
|
name: 'open_devtools',
|
|
11
12
|
description: 'Open a DevTools window for the selected page.',
|
|
@@ -49,6 +50,10 @@ export const getDevtoolsComments = definePageTool(() => ({
|
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
52
|
const bridge = await page.ensureDevToolsCommentBridge(devtoolsPage);
|
|
53
|
+
if (!bridge) {
|
|
54
|
+
response.appendResponseLine(DEVTOOLS_COMMENTS_UNAVAILABLE_MESSAGE);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
52
57
|
const threads = await bridge.getComments(devtoolsPage);
|
|
53
58
|
response.setDevToolsComments(threads);
|
|
54
59
|
},
|
|
@@ -79,6 +84,10 @@ export const resolveDevtoolsComment = definePageTool(() => ({
|
|
|
79
84
|
response.appendResponseLine('DevTools window is not open for this page. Call open_devtools first to open DevTools.');
|
|
80
85
|
return;
|
|
81
86
|
}
|
|
87
|
+
if (!(await page.ensureDevToolsCommentBridge(devtoolsPage))) {
|
|
88
|
+
response.appendResponseLine(DEVTOOLS_COMMENTS_UNAVAILABLE_MESSAGE);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
82
91
|
const { threadId, replyText } = request.params;
|
|
83
92
|
const success = await devtoolsPage.evaluate((id, reply) => {
|
|
84
93
|
return (window.universe?.cd4aBridge?.resolveCommentThread(id, reply) ?? false);
|
|
@@ -125,6 +134,10 @@ export const revealInDevtools = definePageTool(() => ({
|
|
|
125
134
|
response.appendResponseLine('DevTools window is not open for this page. Call open_devtools first to open DevTools.');
|
|
126
135
|
return;
|
|
127
136
|
}
|
|
137
|
+
if (!(await page.ensureDevToolsCommentBridge(devtoolsPage))) {
|
|
138
|
+
response.appendResponseLine(DEVTOOLS_COMMENTS_UNAVAILABLE_MESSAGE);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
128
141
|
const { panelName, uid, reqid } = request.params;
|
|
129
142
|
let backendNodeId;
|
|
130
143
|
let targetId;
|
|
@@ -148,9 +161,15 @@ export const revealInDevtools = definePageTool(() => ({
|
|
|
148
161
|
response.appendResponseLine(`Warning: Could not resolve network request ID ${reqid} to a CDP request ID.`);
|
|
149
162
|
}
|
|
150
163
|
}
|
|
164
|
+
const revealTarget = {
|
|
165
|
+
networkRequestId,
|
|
166
|
+
...(backendNodeId !== undefined
|
|
167
|
+
? { node: { backendNodeId, targetId: targetId ?? '' } }
|
|
168
|
+
: {}),
|
|
169
|
+
};
|
|
151
170
|
await devtoolsPage.evaluate(async (panel, target) => {
|
|
152
171
|
await window.universe?.cd4aBridge?.reveal(panel, target);
|
|
153
|
-
}, panelName
|
|
172
|
+
}, panelName ?? '', revealTarget);
|
|
154
173
|
let targetDesc = '';
|
|
155
174
|
if (uid && backendNodeId !== undefined) {
|
|
156
175
|
targetDesc = ` (revealing element ${uid} [backend node ${backendNodeId}])`;
|
package/build/src/tools/css.js
CHANGED
|
@@ -8,8 +8,10 @@ import { ToolCategory } from './categories.js';
|
|
|
8
8
|
import { definePageTool } from './ToolDefinition.js';
|
|
9
9
|
export const getCssStyles = definePageTool(() => ({
|
|
10
10
|
name: 'get_css_styles',
|
|
11
|
-
description: `Retrieve matched CSS rules, inline styles, inherited styles, and cascade
|
|
12
|
-
|
|
11
|
+
description: `Retrieve matched CSS rules, inline styles (element.style), inherited styles, custom properties, and cascade wrappers (@layer, @media, @container, @scope) for an element identified by its UID.
|
|
12
|
+
Rules are ordered from highest to lowest cascade precedence and include source line numbers (e.g. index:196). Active (winning) declarations have no prefix tag, while (losing) overridden declarations are prefixed with [overloaded].
|
|
13
|
+
Treat the output as authoritative and complete.
|
|
14
|
+
Results are paginated (10 rules per page by default); use pageIdx to page through the remaining rules. Requires a UID from take_snapshot.`,
|
|
13
15
|
annotations: {
|
|
14
16
|
category: ToolCategory.DEBUGGING,
|
|
15
17
|
readOnlyHint: true,
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
import { zod, PredefinedNetworkConditions } from '../third_party/index.js';
|
|
8
|
+
import { FORCED_COLORS_VALUES, PREFERS_CONTRAST_VALUES, PREFERS_REDUCED_MOTION_VALUES, } from '../types.js';
|
|
8
9
|
import { ToolCategory } from './categories.js';
|
|
9
10
|
import { definePageTool, geolocationTransform, viewportTransform, } from './ToolDefinition.js';
|
|
10
11
|
function headerStringTransform(value) {
|
|
@@ -33,7 +34,7 @@ const throttlingOptions = [
|
|
|
33
34
|
];
|
|
34
35
|
export const emulate = definePageTool(() => ({
|
|
35
36
|
name: 'emulate',
|
|
36
|
-
description: `Emulates various features on the target page.`,
|
|
37
|
+
description: `Emulates various features on the target page. Each call replaces all emulation settings (except extraHttpHeaders), so pass all desired settings in a single call.`,
|
|
37
38
|
annotations: {
|
|
38
39
|
category: ToolCategory.EMULATION,
|
|
39
40
|
readOnlyHint: false,
|
|
@@ -57,16 +58,28 @@ export const emulate = definePageTool(() => ({
|
|
|
57
58
|
userAgent: zod
|
|
58
59
|
.string()
|
|
59
60
|
.optional()
|
|
60
|
-
.describe('User agent to emulate.
|
|
61
|
+
.describe('User agent to emulate. Omit or set to empty string to clear the user agent override.'),
|
|
61
62
|
colorScheme: zod
|
|
62
63
|
.enum(['dark', 'light', 'auto'])
|
|
63
64
|
.optional()
|
|
64
|
-
.describe('Emulate the dark or the light mode.
|
|
65
|
+
.describe('Emulate the dark or the light mode. Omit or set to "auto" to reset to the default.'),
|
|
66
|
+
forcedColors: zod
|
|
67
|
+
.enum([...FORCED_COLORS_VALUES, 'auto'])
|
|
68
|
+
.optional()
|
|
69
|
+
.describe('Emulate the `forced-colors` CSS media feature. Omit or set to "auto" to reset to the default.'),
|
|
70
|
+
prefersContrast: zod
|
|
71
|
+
.enum([...PREFERS_CONTRAST_VALUES, 'auto'])
|
|
72
|
+
.optional()
|
|
73
|
+
.describe('Emulate the `prefers-contrast` CSS media feature. Omit or set to "auto" to reset to the default.'),
|
|
74
|
+
prefersReducedMotion: zod
|
|
75
|
+
.enum([...PREFERS_REDUCED_MOTION_VALUES, 'auto'])
|
|
76
|
+
.optional()
|
|
77
|
+
.describe('Emulate the `prefers-reduced-motion` CSS media feature. Omit or set to "auto" to reset to the default.'),
|
|
65
78
|
viewport: zod
|
|
66
79
|
.string()
|
|
67
80
|
.transform(viewportTransform)
|
|
68
81
|
.optional()
|
|
69
|
-
.describe(`Emulate device viewports '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]'. 'touch' and 'mobile' to emulate mobile devices. 'landscape' to emulate landscape mode.`),
|
|
82
|
+
.describe(`Emulate device viewports '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]'. 'touch' and 'mobile' to emulate mobile devices. 'landscape' to emulate landscape mode. Omit to clear the viewport override.`),
|
|
70
83
|
extraHttpHeaders: zod
|
|
71
84
|
.string()
|
|
72
85
|
.transform(headerStringTransform)
|
package/build/src/tools/input.js
CHANGED
|
@@ -576,20 +576,25 @@ export const uploadFile = definePageTool(() => ({
|
|
|
576
576
|
try {
|
|
577
577
|
await handle.uploadFile(...filePaths);
|
|
578
578
|
}
|
|
579
|
-
catch {
|
|
579
|
+
catch (err) {
|
|
580
|
+
if (err instanceof Error &&
|
|
581
|
+
err.message.includes('Multiple file uploads')) {
|
|
582
|
+
throw err;
|
|
583
|
+
}
|
|
580
584
|
// Some sites use a proxy element to trigger file upload instead of
|
|
581
585
|
// a type=file element. In this case, we want to default to
|
|
582
586
|
// Page.waitForFileChooser() and upload the file this way.
|
|
587
|
+
let fileChooser;
|
|
583
588
|
try {
|
|
584
|
-
|
|
589
|
+
[fileChooser] = await Promise.all([
|
|
585
590
|
request.page.pptrPage.waitForFileChooser({ timeout: 3000 }),
|
|
586
591
|
handle.asLocator().click(),
|
|
587
592
|
]);
|
|
588
|
-
await fileChooser.accept(filePaths);
|
|
589
593
|
}
|
|
590
594
|
catch {
|
|
591
595
|
throw new Error(`Failed to upload file. The element could not accept the file directly, and clicking it did not trigger a file chooser.`);
|
|
592
596
|
}
|
|
597
|
+
await fileChooser.accept(filePaths);
|
|
593
598
|
}
|
|
594
599
|
if (request.params.includeSnapshot) {
|
|
595
600
|
response.includeSnapshot();
|
|
@@ -7,7 +7,7 @@ import path from 'node:path';
|
|
|
7
7
|
import { lighthouseRunner, 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,116 @@ 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
|
+
const getString = (value) => {
|
|
25
|
+
return typeof value === 'string' ? value : undefined;
|
|
26
|
+
};
|
|
27
|
+
const toAuditNode = (value) => {
|
|
28
|
+
const node = {};
|
|
29
|
+
const selector = getString(value.selector);
|
|
30
|
+
const snippet = getString(value.snippet);
|
|
31
|
+
const nodeLabel = getString(value.nodeLabel);
|
|
32
|
+
const explanation = getString(value.explanation);
|
|
33
|
+
if (selector) {
|
|
34
|
+
node.selector = selector;
|
|
35
|
+
}
|
|
36
|
+
if (snippet) {
|
|
37
|
+
node.snippet = snippet;
|
|
38
|
+
}
|
|
39
|
+
if (nodeLabel) {
|
|
40
|
+
node.nodeLabel = nodeLabel;
|
|
41
|
+
}
|
|
42
|
+
if (explanation) {
|
|
43
|
+
node.explanation = explanation;
|
|
44
|
+
}
|
|
45
|
+
return node;
|
|
46
|
+
};
|
|
47
|
+
const getNodeKey = (value, nodes) => {
|
|
48
|
+
const id = getString(value.lhId) ?? getString(value.path);
|
|
49
|
+
if (id) {
|
|
50
|
+
return `id:${id}`;
|
|
51
|
+
}
|
|
52
|
+
const selector = getString(value.selector);
|
|
53
|
+
const snippet = getString(value.snippet);
|
|
54
|
+
if (selector || snippet) {
|
|
55
|
+
return `selector:${selector ?? ''}|${snippet ?? ''}`;
|
|
56
|
+
}
|
|
57
|
+
// Nodes without any identifying fields cannot be deduplicated reliably, so
|
|
58
|
+
// each one gets a unique key.
|
|
59
|
+
return `unidentified:${nodes.size}`;
|
|
60
|
+
};
|
|
61
|
+
// Recursively collects node values from audit details. Walking the details
|
|
62
|
+
// generically covers tables and lists of tables alike. Sub-items are skipped:
|
|
63
|
+
// for axe audits they hold related context (e.g. the background element for
|
|
64
|
+
// `color-contrast`) rather than failing elements.
|
|
65
|
+
const collectNodes = (value, nodes) => {
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
for (const item of value) {
|
|
68
|
+
collectNodes(item, nodes);
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!isRecord(value) ||
|
|
73
|
+
value.type === 'debugdata' ||
|
|
74
|
+
value.type === 'subitems') {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (value.type === 'node') {
|
|
78
|
+
const key = getNodeKey(value, nodes);
|
|
79
|
+
// Merge duplicates so that fields such as `explanation` are kept
|
|
80
|
+
// regardless of which occurrence carries them.
|
|
81
|
+
nodes.set(key, { ...toAuditNode(value), ...nodes.get(key) });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
for (const [name, child] of Object.entries(value)) {
|
|
85
|
+
if (name === 'subItems') {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
collectNodes(child, nodes);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const getFailedAudits = (lhr) => {
|
|
92
|
+
const categoriesByAudit = new Map();
|
|
93
|
+
for (const category of Object.values(lhr.categories)) {
|
|
94
|
+
for (const ref of category.auditRefs) {
|
|
95
|
+
const categoryIds = categoriesByAudit.get(ref.id) ?? [];
|
|
96
|
+
categoryIds.push(category.id);
|
|
97
|
+
categoriesByAudit.set(ref.id, categoryIds);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const failedAudits = [];
|
|
101
|
+
for (const audit of Object.values(lhr.audits)) {
|
|
102
|
+
if (audit.score === null || audit.score >= 1) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const nodes = new Map();
|
|
106
|
+
collectNodes(audit.details, nodes);
|
|
107
|
+
const failedAudit = {
|
|
108
|
+
id: audit.id,
|
|
109
|
+
title: audit.title,
|
|
110
|
+
score: audit.score,
|
|
111
|
+
categories: categoriesByAudit.get(audit.id) ?? [],
|
|
112
|
+
nodes: [...nodes.values()].slice(0, MAX_NODES_PER_AUDIT),
|
|
113
|
+
totalNodes: nodes.size,
|
|
114
|
+
};
|
|
115
|
+
if (audit.description) {
|
|
116
|
+
failedAudit.description = audit.description;
|
|
117
|
+
}
|
|
118
|
+
if (audit.displayValue) {
|
|
119
|
+
failedAudit.displayValue = audit.displayValue;
|
|
120
|
+
}
|
|
121
|
+
failedAudits.push(failedAudit);
|
|
122
|
+
}
|
|
123
|
+
return failedAudits;
|
|
124
|
+
};
|
|
18
125
|
export const lighthouseAudit = definePageTool((args) => ({
|
|
19
126
|
name: 'lighthouse_audit',
|
|
20
|
-
description: `Get Lighthouse
|
|
127
|
+
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
128
|
annotations: {
|
|
22
129
|
category: ToolCategory.DEBUGGING,
|
|
23
130
|
readOnlyHint: false,
|
|
@@ -123,7 +230,7 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
123
230
|
title: c.title,
|
|
124
231
|
score: c.score,
|
|
125
232
|
}));
|
|
126
|
-
const failedAudits =
|
|
233
|
+
const failedAudits = getFailedAudits(lhr);
|
|
127
234
|
const passedAudits = Object.values(lhr.audits).filter(a => a.score === 1).length;
|
|
128
235
|
const output = {
|
|
129
236
|
summary: {
|
|
@@ -134,13 +241,14 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
134
241
|
url: lhr.finalDisplayedUrl,
|
|
135
242
|
scores: categoryScores,
|
|
136
243
|
audits: {
|
|
137
|
-
failed: failedAudits,
|
|
244
|
+
failed: failedAudits.length,
|
|
138
245
|
passed: passedAudits,
|
|
139
246
|
},
|
|
140
247
|
timing: {
|
|
141
248
|
total: lhr.timing.total,
|
|
142
249
|
},
|
|
143
250
|
},
|
|
251
|
+
failedAudits,
|
|
144
252
|
reports: reportPaths,
|
|
145
253
|
};
|
|
146
254
|
response.attachLighthouseResult(output);
|