chrome-devtools-mcp 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/BrowserManager.js +401 -0
- package/build/src/McpContext.js +5 -5
- package/build/src/McpPage.js +107 -3
- package/build/src/McpResponse.js +68 -3
- package/build/src/ToolHandler.js +172 -118
- package/build/src/bin/chrome-devtools-mcp-main.js +11 -6
- package/build/src/bin/chrome-devtools.js +6 -12
- package/build/src/collectors/PageCollector.js +66 -3
- package/build/src/config/browser-options.js +2 -0
- package/build/src/config/category-options.js +13 -4
- package/build/src/config/cli-commands.js +26 -0
- package/build/src/config/cli-options.js +32 -0
- package/build/src/config/mcp-options.js +40 -1
- package/build/src/devtools/DevToolsCommentBridge.js +91 -0
- package/build/src/formatters/CommentFormatter.js +82 -0
- package/build/src/formatters/CssFormatter.js +812 -0
- package/build/src/index.js +53 -72
- package/build/src/processors/ChunkedTraceParser.js +361 -0
- package/build/src/processors/PerformanceTrace.js +60 -13
- package/build/src/telemetry/ClearcutLogger.js +91 -34
- package/build/src/telemetry/metricsRegistry.js +3 -0
- package/build/src/telemetry/persistence.js +17 -7
- package/build/src/telemetry/transformation.js +53 -4
- package/build/src/telemetry/types.js +1 -0
- package/build/src/third_party/THIRD_PARTY_NOTICES +685 -131
- package/build/src/third_party/bundled-packages.json +6 -3
- package/build/src/third_party/devtools-formatter-worker.js +136 -5
- package/build/src/third_party/devtools-heap-snapshot-worker.js +567 -6
- package/build/src/third_party/index.js +54945 -35497
- package/build/src/third_party/issue-descriptions/webInstallManifestMissingId.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallManifestMissingNameOrShortName.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallManifestParsingOrNetworkError.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallNoManifest.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallStartUrlInvalid.md +3 -0
- package/build/src/tools/ToolDefinition.js +13 -21
- package/build/src/tools/comments.js +169 -0
- package/build/src/tools/console.js +3 -3
- package/build/src/tools/css.js +45 -0
- package/build/src/tools/emulation.js +5 -5
- package/build/src/tools/extensions.js +10 -10
- package/build/src/tools/input.js +159 -87
- package/build/src/tools/lighthouse.js +18 -7
- package/build/src/tools/memory.js +26 -26
- package/build/src/tools/network.js +4 -4
- package/build/src/tools/pages.js +14 -14
- package/build/src/tools/performance.js +6 -6
- package/build/src/tools/pwa.js +8 -8
- package/build/src/tools/screencast.js +4 -4
- package/build/src/tools/screenshot.js +2 -2
- package/build/src/tools/script.js +7 -7
- package/build/src/tools/slim/tools.js +5 -5
- package/build/src/tools/snapshot.js +4 -4
- package/build/src/tools/thirdPartyDeveloper.js +4 -4
- package/build/src/tools/tools.js +6 -9
- package/build/src/tools/webmcp.js +4 -4
- package/build/src/types.js +4 -1
- package/build/src/utils/WaitForHelper.js +14 -8
- package/build/src/utils/logger.js +7 -6
- package/build/src/version.js +1 -1
- package/package.json +8 -5
- package/skills/chrome-devtools/SKILL.md +2 -1
- package/skills/chrome-devtools-cli/SKILL.md +2 -0
- package/build/src/browser.js +0 -233
- package/build/src/third_party/issue-descriptions/cookieExcludeBlockedWithinRelatedWebsiteSet.md +0 -4
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { FakeIssuesManager } from '../devtools/DevtoolsUtils.js';
|
|
7
|
-
import { DevTools } from '../third_party/index.js';
|
|
7
|
+
import { DevTools, FrameEvent } from '../third_party/index.js';
|
|
8
8
|
import { createIdGenerator, stableIdSymbol, } from '../utils/id.js';
|
|
9
9
|
import { logger } from '../utils/logger.js';
|
|
10
10
|
export class UncaughtError {
|
|
@@ -18,6 +18,8 @@ export class UncaughtError {
|
|
|
18
18
|
export class PageCollector {
|
|
19
19
|
pptrPage;
|
|
20
20
|
#listeners;
|
|
21
|
+
#pendingSameDocumentNavigation = false;
|
|
22
|
+
#frameNavigatedWithinDocumentTarget;
|
|
21
23
|
maxNavigationSaved = 3;
|
|
22
24
|
/**
|
|
23
25
|
* This maps a Page to a list of navigations with a sub-list
|
|
@@ -27,6 +29,7 @@ export class PageCollector {
|
|
|
27
29
|
storage = [[]];
|
|
28
30
|
constructor(page, listeners, maxResourcesPerNavigation) {
|
|
29
31
|
this.pptrPage = page;
|
|
32
|
+
this.#attachFrameNavigatedWithinDocumentListener();
|
|
30
33
|
const idGenerator = createIdGenerator();
|
|
31
34
|
const listenerMap = listeners(value => {
|
|
32
35
|
const withId = value;
|
|
@@ -42,6 +45,18 @@ export class PageCollector {
|
|
|
42
45
|
if (frame !== this.pptrPage.mainFrame()) {
|
|
43
46
|
return;
|
|
44
47
|
}
|
|
48
|
+
// Re-attach the listener to the current main frame: a cross-document
|
|
49
|
+
// navigation may have replaced the frame object, so the reference
|
|
50
|
+
// captured at construction time would be stale.
|
|
51
|
+
this.#attachFrameNavigatedWithinDocumentListener();
|
|
52
|
+
// Same-document (SPA) navigations also emit `framenavigated`, but they
|
|
53
|
+
// must not rotate the retained history. Puppeteer emits
|
|
54
|
+
// `FrameNavigatedWithinDocument` right before `FrameNavigated` for such
|
|
55
|
+
// navigations, so consume the flag here to skip the split.
|
|
56
|
+
if (this.#pendingSameDocumentNavigation) {
|
|
57
|
+
this.#pendingSameDocumentNavigation = false;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
45
60
|
this.splitAfterNavigation();
|
|
46
61
|
};
|
|
47
62
|
for (const [name, listener] of Object.entries(listenerMap)) {
|
|
@@ -50,12 +65,30 @@ export class PageCollector {
|
|
|
50
65
|
this.#listeners = listenerMap;
|
|
51
66
|
}
|
|
52
67
|
dispose() {
|
|
68
|
+
this.#detachFrameNavigatedWithinDocumentListener();
|
|
53
69
|
if (this.#listeners) {
|
|
54
70
|
for (const [name, listener] of Object.entries(this.#listeners)) {
|
|
55
71
|
this.pptrPage.off(name, listener);
|
|
56
72
|
}
|
|
57
73
|
}
|
|
58
74
|
}
|
|
75
|
+
// Puppeteer emits this right before the page-level navigation event for
|
|
76
|
+
// same-document (SPA) navigations, which lets `framenavigated` skip the
|
|
77
|
+
// history rotation for those navigations.
|
|
78
|
+
#onFrameNavigatedWithinDocument = () => {
|
|
79
|
+
this.#pendingSameDocumentNavigation = true;
|
|
80
|
+
};
|
|
81
|
+
#attachFrameNavigatedWithinDocumentListener() {
|
|
82
|
+
this.#detachFrameNavigatedWithinDocumentListener();
|
|
83
|
+
this.#frameNavigatedWithinDocumentTarget = this.pptrPage.mainFrame();
|
|
84
|
+
this.#frameNavigatedWithinDocumentTarget.on(FrameEvent.FrameNavigatedWithinDocument, this.#onFrameNavigatedWithinDocument);
|
|
85
|
+
}
|
|
86
|
+
#detachFrameNavigatedWithinDocumentListener() {
|
|
87
|
+
if (this.#frameNavigatedWithinDocumentTarget) {
|
|
88
|
+
this.#frameNavigatedWithinDocumentTarget.off(FrameEvent.FrameNavigatedWithinDocument, this.#onFrameNavigatedWithinDocument);
|
|
89
|
+
this.#frameNavigatedWithinDocumentTarget = undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
59
92
|
splitAfterNavigation() {
|
|
60
93
|
// Add the latest navigation first
|
|
61
94
|
this.storage.unshift([]);
|
|
@@ -94,9 +127,10 @@ export class PageCollector {
|
|
|
94
127
|
}
|
|
95
128
|
}
|
|
96
129
|
export class ConsoleCollector extends PageCollector {
|
|
130
|
+
static MAX_MESSAGES_PER_NAVIGATION = 10_000;
|
|
97
131
|
#subscriber;
|
|
98
|
-
constructor(page, listeners) {
|
|
99
|
-
super(page, listeners);
|
|
132
|
+
constructor(page, listeners, maxMessagesPerNavigation = ConsoleCollector.MAX_MESSAGES_PER_NAVIGATION) {
|
|
133
|
+
super(page, listeners, maxMessagesPerNavigation);
|
|
100
134
|
this.#subscriber = new PageEventSubscriber(this.pptrPage);
|
|
101
135
|
this.#subscriber.subscribe();
|
|
102
136
|
}
|
|
@@ -113,6 +147,8 @@ class PageEventSubscriber {
|
|
|
113
147
|
#page;
|
|
114
148
|
#session;
|
|
115
149
|
#targetId;
|
|
150
|
+
#pendingSameDocumentNavigation = false;
|
|
151
|
+
#frameNavigatedWithinDocumentTarget;
|
|
116
152
|
constructor(page) {
|
|
117
153
|
this.#page = page;
|
|
118
154
|
// @ts-expect-error use existing CDP client (internal Puppeteer API).
|
|
@@ -133,10 +169,12 @@ class PageEventSubscriber {
|
|
|
133
169
|
this.#page.on('framenavigated', this.#onFrameNavigated);
|
|
134
170
|
this.#page.on('issue', this.#onIssueAdded);
|
|
135
171
|
this.#session.on('Runtime.exceptionThrown', this.#onExceptionThrown);
|
|
172
|
+
this.#attachFrameNavigatedWithinDocumentListener();
|
|
136
173
|
}
|
|
137
174
|
unsubscribe() {
|
|
138
175
|
this.#seenKeys.clear();
|
|
139
176
|
this.#seenIssues.clear();
|
|
177
|
+
this.#detachFrameNavigatedWithinDocumentListener();
|
|
140
178
|
this.#page.off('framenavigated', this.#onFrameNavigated);
|
|
141
179
|
this.#page.off('issue', this.#onIssueAdded);
|
|
142
180
|
this.#session.off('Runtime.exceptionThrown', this.#onExceptionThrown);
|
|
@@ -160,10 +198,35 @@ class PageEventSubscriber {
|
|
|
160
198
|
if (frame !== frame.page().mainFrame()) {
|
|
161
199
|
return;
|
|
162
200
|
}
|
|
201
|
+
// Re-attach the listener to the current main frame: a cross-document
|
|
202
|
+
// navigation may have replaced the frame object, so the reference
|
|
203
|
+
// captured at construction time would be stale.
|
|
204
|
+
this.#attachFrameNavigatedWithinDocumentListener();
|
|
205
|
+
if (this.#pendingSameDocumentNavigation) {
|
|
206
|
+
this.#pendingSameDocumentNavigation = false;
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
163
209
|
this.#seenKeys.clear();
|
|
164
210
|
this.#seenIssues.clear();
|
|
165
211
|
this.#resetIssueAggregator();
|
|
166
212
|
};
|
|
213
|
+
// Puppeteer emits this right before the page-level navigation event for
|
|
214
|
+
// same-document (SPA) navigations, which lets `framenavigated` skip the
|
|
215
|
+
// issue aggregation reset for those navigations.
|
|
216
|
+
#onFrameNavigatedWithinDocument = () => {
|
|
217
|
+
this.#pendingSameDocumentNavigation = true;
|
|
218
|
+
};
|
|
219
|
+
#attachFrameNavigatedWithinDocumentListener() {
|
|
220
|
+
this.#detachFrameNavigatedWithinDocumentListener();
|
|
221
|
+
this.#frameNavigatedWithinDocumentTarget = this.#page.mainFrame();
|
|
222
|
+
this.#frameNavigatedWithinDocumentTarget.on(FrameEvent.FrameNavigatedWithinDocument, this.#onFrameNavigatedWithinDocument);
|
|
223
|
+
}
|
|
224
|
+
#detachFrameNavigatedWithinDocumentListener() {
|
|
225
|
+
if (this.#frameNavigatedWithinDocumentTarget) {
|
|
226
|
+
this.#frameNavigatedWithinDocumentTarget.off(FrameEvent.FrameNavigatedWithinDocument, this.#onFrameNavigatedWithinDocument);
|
|
227
|
+
this.#frameNavigatedWithinDocumentTarget = undefined;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
167
230
|
#onIssueAdded = (inspectorIssue) => {
|
|
168
231
|
try {
|
|
169
232
|
// @ts-expect-error The types are missmatched but they
|
|
@@ -110,10 +110,12 @@ export const browserOptions = {
|
|
|
110
110
|
},
|
|
111
111
|
chromeArg: {
|
|
112
112
|
type: 'array',
|
|
113
|
+
string: true,
|
|
113
114
|
describe: 'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
|
|
114
115
|
},
|
|
115
116
|
ignoreDefaultChromeArg: {
|
|
116
117
|
type: 'array',
|
|
118
|
+
string: true,
|
|
117
119
|
describe: 'Explicitly disable default arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
|
|
118
120
|
},
|
|
119
121
|
};
|
|
@@ -5,8 +5,12 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ToolCategory } from '../tools/categories.js';
|
|
7
7
|
const categoryOverrides = {
|
|
8
|
-
[ToolCategory.INPUT]: {
|
|
9
|
-
|
|
8
|
+
[ToolCategory.INPUT]: {
|
|
9
|
+
hidden: false,
|
|
10
|
+
},
|
|
11
|
+
[ToolCategory.NAVIGATION]: {
|
|
12
|
+
hidden: false,
|
|
13
|
+
},
|
|
10
14
|
[ToolCategory.EMULATION]: {
|
|
11
15
|
hidden: false,
|
|
12
16
|
},
|
|
@@ -16,11 +20,16 @@ const categoryOverrides = {
|
|
|
16
20
|
[ToolCategory.NETWORK]: {
|
|
17
21
|
hidden: false,
|
|
18
22
|
},
|
|
19
|
-
[ToolCategory.DEBUGGING]: {
|
|
20
|
-
|
|
23
|
+
[ToolCategory.DEBUGGING]: {
|
|
24
|
+
hidden: false,
|
|
25
|
+
},
|
|
26
|
+
[ToolCategory.MEMORY]: {
|
|
27
|
+
hidden: false,
|
|
28
|
+
},
|
|
21
29
|
[ToolCategory.WEBMCP]: {
|
|
22
30
|
describe: 'Set to true to enable debugging WebMCP tools. Requires Chrome 150+ with the following flag: `--enable-features=WebMCP`',
|
|
23
31
|
offByDefault: true,
|
|
32
|
+
hidden: false,
|
|
24
33
|
},
|
|
25
34
|
[ToolCategory.EXTENSIONS]: {
|
|
26
35
|
describe: 'Set to true to include tools related to extensions. Note: This feature is currently only supported with a pipe connection. autoConnect, browserUrl, and wsEndpoint are not supported with this feature until 149 will be released.',
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Builds the yargs command string and usage line for a CLI command.
|
|
8
|
+
*
|
|
9
|
+
* Optional args are rendered as `[--flag]` in the usage line only: as part of
|
|
10
|
+
* the command string yargs parses each one as a trailing positional, and a
|
|
11
|
+
* variadic positional has to be the last one.
|
|
12
|
+
*/
|
|
13
|
+
export function buildCommand(commandName, args) {
|
|
14
|
+
let command = commandName;
|
|
15
|
+
let flags = '';
|
|
16
|
+
for (const [name, arg] of Object.entries(args)) {
|
|
17
|
+
if (arg.required) {
|
|
18
|
+
command += arg.type === 'array' ? ` <${name}..>` : ` <${name}>`;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
flags += ` [--${name}]`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return { command, usage: `$0 ${command}${flags}` };
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=cli-commands.js.map
|
|
@@ -348,6 +348,38 @@ export const commands = {
|
|
|
348
348
|
},
|
|
349
349
|
},
|
|
350
350
|
},
|
|
351
|
+
get_css_styles: {
|
|
352
|
+
description: 'Retrieve matched CSS rules, inline styles, inherited styles, and cascade information for an element identified by its UID.\nUse this tool to debug why specific CSS properties are applied, overridden, or conflicting. Results are paginated and return 10 rules per page by default; use pageIdx to page through the remaining rules. Requires a UID from take_snapshot.',
|
|
353
|
+
category: 'Debugging',
|
|
354
|
+
args: {
|
|
355
|
+
pageId: {
|
|
356
|
+
name: 'pageId',
|
|
357
|
+
type: 'number',
|
|
358
|
+
description: 'Targets a specific page by ID.',
|
|
359
|
+
required: true,
|
|
360
|
+
},
|
|
361
|
+
uid: {
|
|
362
|
+
name: 'uid',
|
|
363
|
+
type: 'string',
|
|
364
|
+
description: 'The uid of the element on the page from the page content snapshot to inspect CSS styles for',
|
|
365
|
+
required: true,
|
|
366
|
+
},
|
|
367
|
+
pageSize: {
|
|
368
|
+
name: 'pageSize',
|
|
369
|
+
type: 'integer',
|
|
370
|
+
description: 'Maximum number of CSS rules to return per page. Defaults to 10.',
|
|
371
|
+
required: false,
|
|
372
|
+
default: 10,
|
|
373
|
+
},
|
|
374
|
+
pageIdx: {
|
|
375
|
+
name: 'pageIdx',
|
|
376
|
+
type: 'integer',
|
|
377
|
+
description: 'Page number to return (0-based). Defaults to 0 (the first page).',
|
|
378
|
+
required: false,
|
|
379
|
+
default: 0,
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
},
|
|
351
383
|
get_heapsnapshot_class_nodes: {
|
|
352
384
|
description: 'Loads a memory heapsnapshot and returns instances of a specific class with their IDs. (requires flag: --memoryDebugging=true)',
|
|
353
385
|
category: 'Memory',
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { yargs, hideBin } from '../third_party/index.js';
|
|
7
7
|
import os from 'node:os';
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
8
9
|
export const DEFAULT_FILESYSTEM_ROOT = [os.tmpdir()];
|
|
9
10
|
import { getCategoryOptions } from './category-options.js';
|
|
10
11
|
import { getBrowserOptions } from './browser-options.js';
|
|
@@ -13,7 +14,7 @@ export const mcpOptions = {
|
|
|
13
14
|
...getBrowserOptions(),
|
|
14
15
|
logFile: {
|
|
15
16
|
type: 'string',
|
|
16
|
-
describe: 'Path to a file to write debug logs to. Set the env variable `
|
|
17
|
+
describe: 'Path to a file to write debug logs to. Set the env variable `NODE_DEBUG` to `*` to enable verbose logs. Useful for submitting bug reports.',
|
|
17
18
|
},
|
|
18
19
|
viewport: {
|
|
19
20
|
type: 'string',
|
|
@@ -41,6 +42,12 @@ export const mcpOptions = {
|
|
|
41
42
|
describe: 'Require pageId on page-scoped tools and route requests by page ID (useful for concurrent agent sessions). Use --no-page-id-routing to disable.',
|
|
42
43
|
default: true,
|
|
43
44
|
},
|
|
45
|
+
devtoolsComments: {
|
|
46
|
+
type: 'boolean',
|
|
47
|
+
describe: 'Whether to enable DevTools comments tools. Internal WIP feature.',
|
|
48
|
+
hidden: true,
|
|
49
|
+
default: false,
|
|
50
|
+
},
|
|
44
51
|
experimentalDevtools: {
|
|
45
52
|
type: 'boolean',
|
|
46
53
|
describe: 'Whether to enable automation over DevTools targets',
|
|
@@ -105,11 +112,13 @@ export const mcpOptions = {
|
|
|
105
112
|
},
|
|
106
113
|
blockedUrlPattern: {
|
|
107
114
|
type: 'array',
|
|
115
|
+
string: true,
|
|
108
116
|
describe: "Restricts browser's network access by blocking specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Silently detaches from targets with blocked URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns.",
|
|
109
117
|
conflicts: ['allowedUrlPattern'],
|
|
110
118
|
},
|
|
111
119
|
allowedUrlPattern: {
|
|
112
120
|
type: 'array',
|
|
121
|
+
string: true,
|
|
113
122
|
describe: "Restricts browser's network access by allowing only specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns.",
|
|
114
123
|
conflicts: ['blockedUrlPattern'],
|
|
115
124
|
},
|
|
@@ -217,11 +226,16 @@ export const mcpOptions = {
|
|
|
217
226
|
},
|
|
218
227
|
filesystemRoot: {
|
|
219
228
|
type: 'array',
|
|
229
|
+
string: true,
|
|
220
230
|
alias: 'workspace',
|
|
221
231
|
default: DEFAULT_FILESYSTEM_ROOT,
|
|
222
232
|
defaultDescription: 'OS temp directory',
|
|
223
233
|
describe: 'A directory that filesystem tools are allowed to access. May be specified more than once.',
|
|
224
234
|
},
|
|
235
|
+
config: {
|
|
236
|
+
type: 'string',
|
|
237
|
+
describe: 'Path to JSON configuration file.',
|
|
238
|
+
},
|
|
225
239
|
};
|
|
226
240
|
export function getMcpOptionsForViaCli() {
|
|
227
241
|
if (!('default' in mcpOptions.headless)) {
|
|
@@ -368,6 +382,31 @@ export function parser(version, argv = process.argv, env = process.env) {
|
|
|
368
382
|
],
|
|
369
383
|
]);
|
|
370
384
|
return yargsInstance
|
|
385
|
+
.config('config', 'Path to JSON configuration file', configPath => {
|
|
386
|
+
try {
|
|
387
|
+
const parsed = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
388
|
+
if (typeof parsed !== 'object' ||
|
|
389
|
+
parsed === null ||
|
|
390
|
+
Array.isArray(parsed)) {
|
|
391
|
+
throw new Error('Config must be a JSON object');
|
|
392
|
+
}
|
|
393
|
+
yargs()
|
|
394
|
+
.parserConfiguration({
|
|
395
|
+
'strip-aliased': true,
|
|
396
|
+
'camel-case-expansion': false,
|
|
397
|
+
})
|
|
398
|
+
.options(options)
|
|
399
|
+
.config(parsed)
|
|
400
|
+
.strict()
|
|
401
|
+
.fail(false)
|
|
402
|
+
.exitProcess(false)
|
|
403
|
+
.parseSync([]);
|
|
404
|
+
return parsed;
|
|
405
|
+
}
|
|
406
|
+
catch (err) {
|
|
407
|
+
throw new Error(`Invalid JSON config file: ${err.message}`);
|
|
408
|
+
}
|
|
409
|
+
})
|
|
371
410
|
.wrap(Math.min(120, yargsInstance.terminalWidth()))
|
|
372
411
|
.help()
|
|
373
412
|
.version(version);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { logger } from '../utils/logger.js';
|
|
7
|
+
const DEFAULT_DEBOUNCE_MS = 200;
|
|
8
|
+
/**
|
|
9
|
+
* Manages the bidirectional bridge between DevTools frontend comments
|
|
10
|
+
* and the MCP server notification system.
|
|
11
|
+
*/
|
|
12
|
+
export class DevToolsCommentBridge {
|
|
13
|
+
#onNotification;
|
|
14
|
+
#debounceMs;
|
|
15
|
+
#commentDebounceTimer;
|
|
16
|
+
#attachedPages = new Set();
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.#onNotification = options?.onNotification;
|
|
19
|
+
this.#debounceMs = options?.debounceMs ?? DEFAULT_DEBOUNCE_MS;
|
|
20
|
+
}
|
|
21
|
+
isAttached(devtoolsPage) {
|
|
22
|
+
return this.#attachedPages.has(devtoolsPage);
|
|
23
|
+
}
|
|
24
|
+
async attach(devtoolsPage) {
|
|
25
|
+
if (this.#attachedPages.has(devtoolsPage)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.#attachedPages.add(devtoolsPage);
|
|
29
|
+
try {
|
|
30
|
+
await devtoolsPage.exposeFunction('__onDevToolsCommentEvent', () => {
|
|
31
|
+
this.#handleCommentEvent();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
logger?.('DevToolsCommentBridge: exposeFunction already bound or failed', e);
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
await devtoolsPage.evaluate(() => {
|
|
39
|
+
window.__onDevToolsCommentListener = () => {
|
|
40
|
+
window.__onDevToolsCommentEvent?.();
|
|
41
|
+
};
|
|
42
|
+
window.universe?.cd4aBridge?.addEventListener('CommentThreadsChanged', window.__onDevToolsCommentListener);
|
|
43
|
+
window.universe?.cd4aBridge?.setAgentAttached(true);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
logger?.('DevToolsCommentBridge: evaluate failed', e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async getComments(devtoolsPage) {
|
|
51
|
+
return await devtoolsPage.evaluate(() => {
|
|
52
|
+
window.universe?.cd4aBridge?.setAgentAttached(true);
|
|
53
|
+
return window.universe?.cd4aBridge?.getCommentThreads() ?? [];
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
#handleCommentEvent() {
|
|
57
|
+
if (this.#commentDebounceTimer) {
|
|
58
|
+
clearTimeout(this.#commentDebounceTimer);
|
|
59
|
+
}
|
|
60
|
+
this.#commentDebounceTimer = setTimeout(() => {
|
|
61
|
+
this.#onNotification?.('DevTools comment threads updated');
|
|
62
|
+
}, this.#debounceMs);
|
|
63
|
+
}
|
|
64
|
+
dispose() {
|
|
65
|
+
if (this.#commentDebounceTimer) {
|
|
66
|
+
clearTimeout(this.#commentDebounceTimer);
|
|
67
|
+
this.#commentDebounceTimer = undefined;
|
|
68
|
+
}
|
|
69
|
+
for (const page of this.#attachedPages) {
|
|
70
|
+
try {
|
|
71
|
+
const result = page.evaluate(() => {
|
|
72
|
+
if (window.__onDevToolsCommentListener) {
|
|
73
|
+
window.universe?.cd4aBridge?.removeEventListener?.('CommentThreadsChanged', window.__onDevToolsCommentListener);
|
|
74
|
+
delete window.__onDevToolsCommentListener;
|
|
75
|
+
}
|
|
76
|
+
window.universe?.cd4aBridge?.setAgentAttached(false);
|
|
77
|
+
});
|
|
78
|
+
if (result && typeof result.catch === 'function') {
|
|
79
|
+
void result.catch(e => {
|
|
80
|
+
logger?.('DevToolsCommentBridge: failed to remove event listener', e);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
logger?.('DevToolsCommentBridge: failed to remove event listener', e);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
this.#attachedPages.clear();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=DevToolsCommentBridge.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
function formatCommentThread(thread) {
|
|
7
|
+
const lines = [
|
|
8
|
+
`### Thread: ${thread.id}`,
|
|
9
|
+
`- Comment: ${thread.text}`,
|
|
10
|
+
];
|
|
11
|
+
if (thread.elementUid) {
|
|
12
|
+
lines.push(`- Target element (snapshot UID): ${thread.elementUid}`);
|
|
13
|
+
}
|
|
14
|
+
if (thread.reqid !== undefined) {
|
|
15
|
+
lines.push(`- Network request ID (reqid): ${thread.reqid}`);
|
|
16
|
+
}
|
|
17
|
+
if (thread.editor) {
|
|
18
|
+
const location = thread.editor.filePath
|
|
19
|
+
? `${thread.editor.filePath}:${thread.editor.lineNumber}`
|
|
20
|
+
: `line ${thread.editor.lineNumber}`;
|
|
21
|
+
lines.push(`- Editor location: ${location}`);
|
|
22
|
+
}
|
|
23
|
+
return lines.join('\n');
|
|
24
|
+
}
|
|
25
|
+
function formatComments(threads) {
|
|
26
|
+
if (threads.length === 0) {
|
|
27
|
+
return 'No open DevTools comments found.';
|
|
28
|
+
}
|
|
29
|
+
const lines = [
|
|
30
|
+
`Found ${threads.length} DevTools comment thread(s):`,
|
|
31
|
+
];
|
|
32
|
+
for (const thread of threads) {
|
|
33
|
+
lines.push(`\n${formatCommentThread(thread)}`);
|
|
34
|
+
}
|
|
35
|
+
return lines.join('\n');
|
|
36
|
+
}
|
|
37
|
+
export class CommentFormatter {
|
|
38
|
+
#threads;
|
|
39
|
+
constructor(threads) {
|
|
40
|
+
this.#threads = threads;
|
|
41
|
+
}
|
|
42
|
+
static async from(threads, options) {
|
|
43
|
+
const structuredThreads = [];
|
|
44
|
+
for (const thread of threads) {
|
|
45
|
+
let elementUid;
|
|
46
|
+
const resolveBackendNodeId = options?.resolveBackendNodeId;
|
|
47
|
+
if (thread.backendNodeId !== undefined && resolveBackendNodeId) {
|
|
48
|
+
elementUid = await resolveBackendNodeId(thread.backendNodeId);
|
|
49
|
+
}
|
|
50
|
+
let reqid;
|
|
51
|
+
const resolveCdpRequestId = options?.resolveCdpRequestId;
|
|
52
|
+
if (thread.networkRequestId !== undefined && resolveCdpRequestId) {
|
|
53
|
+
reqid = resolveCdpRequestId(thread.networkRequestId);
|
|
54
|
+
}
|
|
55
|
+
const item = {
|
|
56
|
+
id: thread.id,
|
|
57
|
+
text: thread.text,
|
|
58
|
+
};
|
|
59
|
+
if (elementUid) {
|
|
60
|
+
item.elementUid = elementUid;
|
|
61
|
+
}
|
|
62
|
+
if (reqid !== undefined) {
|
|
63
|
+
item.reqid = reqid;
|
|
64
|
+
}
|
|
65
|
+
if (thread.editor) {
|
|
66
|
+
item.editor = thread.editor;
|
|
67
|
+
}
|
|
68
|
+
structuredThreads.push(item);
|
|
69
|
+
}
|
|
70
|
+
return new CommentFormatter(structuredThreads);
|
|
71
|
+
}
|
|
72
|
+
static formatThread(thread) {
|
|
73
|
+
return formatCommentThread(thread);
|
|
74
|
+
}
|
|
75
|
+
toJSON() {
|
|
76
|
+
return [...this.#threads];
|
|
77
|
+
}
|
|
78
|
+
toString() {
|
|
79
|
+
return formatComments(this.toJSON());
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=CommentFormatter.js.map
|