chrome-devtools-mcp 1.11.0 → 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 +27 -18
- package/build/src/McpContext.js +435 -87
- package/build/src/McpPage.js +189 -59
- package/build/src/McpResponse.js +61 -44
- package/build/src/TextSnapshot.js +37 -18
- package/build/src/ToolHandler.js +256 -135
- package/build/src/bin/chrome-devtools-mcp-main.js +6 -4
- package/build/src/bin/chrome-devtools.js +4 -4
- package/build/src/collectors/PageCollector.js +13 -9
- package/build/src/collectors/ServiceWorkerCollector.js +2 -2
- package/build/src/collectors/constants.js +7 -0
- package/build/src/config/ConfigParser.js +44 -149
- package/build/src/config/ConfigWatcher.js +3 -2
- package/build/src/config/ServerConfig.js +251 -0
- package/build/src/config/browser-options.js +13 -4
- package/build/src/config/cli-options.js +35 -19
- package/build/src/config/mcp-options.js +61 -35
- package/build/src/config/puppeteer-options.js +4 -2
- package/build/src/daemon/client.js +3 -3
- package/build/src/daemon/daemon.js +7 -3
- package/build/src/daemon/utils.js +2 -1
- package/build/src/devtools/DevToolsCommentBridge.js +28 -5
- package/build/src/devtools/DevtoolsUtils.js +49 -12
- package/build/src/formatters/ConsoleFormatter.js +28 -1
- package/build/src/formatters/HeapSnapshotFormatter.js +14 -18
- package/build/src/formatters/NetworkFormatter.js +54 -15
- package/build/src/formatters/RemoteObjectFormatter.js +231 -0
- package/build/src/formatters/SnapshotFormatter.js +13 -3
- package/build/src/index.js +256 -104
- package/build/src/processors/HeapSnapshotManager.js +390 -128
- package/build/src/third_party/THIRD_PARTY_NOTICES +542 -445
- package/build/src/third_party/bundled-packages.json +2 -2
- package/build/src/third_party/cli.js +9239 -0
- package/build/src/third_party/devtools-formatter-worker.js +3089 -2438
- package/build/src/third_party/devtools-heap-snapshot-worker.js +172 -1
- package/build/src/third_party/index.js +52247 -55764
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
- package/build/src/tools/ToolDefinition.js +90 -12
- package/build/src/tools/comments.js +42 -3
- package/build/src/tools/console.js +6 -4
- package/build/src/tools/css.js +1 -0
- package/build/src/tools/emulation.js +5 -4
- package/build/src/tools/extensions.js +5 -0
- package/build/src/tools/input.js +21 -6
- package/build/src/tools/lighthouse.js +24 -8
- package/build/src/tools/memory.js +59 -53
- package/build/src/tools/network.js +5 -4
- package/build/src/tools/pages.js +48 -6
- package/build/src/tools/performance.js +7 -4
- package/build/src/tools/pwa.js +7 -0
- package/build/src/tools/screencast.js +3 -1
- package/build/src/tools/screenshot.js +23 -7
- package/build/src/tools/script.js +38 -6
- package/build/src/tools/slim/tools.js +21 -5
- package/build/src/tools/snapshot.js +13 -3
- package/build/src/tools/thirdPartyDeveloper.js +3 -1
- package/build/src/tools/webmcp.js +2 -0
- package/build/src/utils/TaskRunner.js +136 -0
- package/build/src/utils/WaitForHelper.js +1 -1
- package/build/src/utils/bytes.js +2 -12
- package/build/src/utils/check-for-updates.js +1 -1
- package/build/src/utils/disclaimers.js +27 -0
- package/build/src/utils/keyboard.js +14 -2
- package/build/src/utils/logger.js +69 -0
- package/build/src/utils/resourceType.js +27 -0
- package/build/src/utils/text.js +29 -0
- package/build/src/utils/timeout.js +14 -0
- package/build/src/utils/url.js +41 -0
- package/build/src/version.js +1 -1
- package/package.json +5 -4
- package/skills/a11y-debugging/SKILL.md +3 -8
|
@@ -39,16 +39,18 @@ export const commands = {
|
|
|
39
39
|
pageIdx: {
|
|
40
40
|
name: 'pageIdx',
|
|
41
41
|
type: 'integer',
|
|
42
|
-
description: 'The zero-based page index. Defaults to 0.',
|
|
42
|
+
description: 'The zero-based page index. Defaults to 0 (the first page).',
|
|
43
43
|
required: false,
|
|
44
44
|
positional: false,
|
|
45
|
+
default: 0,
|
|
45
46
|
},
|
|
46
47
|
pageSize: {
|
|
47
48
|
name: 'pageSize',
|
|
48
49
|
type: 'integer',
|
|
49
|
-
description: 'The number of
|
|
50
|
+
description: 'The maximum number of items to return per page. Defaults to 50.',
|
|
50
51
|
required: false,
|
|
51
52
|
positional: false,
|
|
53
|
+
default: 50,
|
|
52
54
|
},
|
|
53
55
|
},
|
|
54
56
|
},
|
|
@@ -188,16 +190,18 @@ export const commands = {
|
|
|
188
190
|
pageIdx: {
|
|
189
191
|
name: 'pageIdx',
|
|
190
192
|
type: 'integer',
|
|
191
|
-
description: 'The page index
|
|
193
|
+
description: 'The zero-based page index. Defaults to 0 (the first page).',
|
|
192
194
|
required: false,
|
|
193
195
|
positional: false,
|
|
196
|
+
default: 0,
|
|
194
197
|
},
|
|
195
198
|
pageSize: {
|
|
196
199
|
name: 'pageSize',
|
|
197
200
|
type: 'integer',
|
|
198
|
-
description: 'The page
|
|
201
|
+
description: 'The maximum number of items to return per page. Defaults to 50.',
|
|
199
202
|
required: false,
|
|
200
203
|
positional: false,
|
|
204
|
+
default: 50,
|
|
201
205
|
},
|
|
202
206
|
},
|
|
203
207
|
},
|
|
@@ -588,16 +592,18 @@ export const commands = {
|
|
|
588
592
|
pageIdx: {
|
|
589
593
|
name: 'pageIdx',
|
|
590
594
|
type: 'integer',
|
|
591
|
-
description: 'The page index
|
|
595
|
+
description: 'The zero-based page index. Defaults to 0 (the first page).',
|
|
592
596
|
required: false,
|
|
593
597
|
positional: false,
|
|
598
|
+
default: 0,
|
|
594
599
|
},
|
|
595
600
|
pageSize: {
|
|
596
601
|
name: 'pageSize',
|
|
597
602
|
type: 'integer',
|
|
598
|
-
description: 'The page
|
|
603
|
+
description: 'The maximum number of items to return per page. Defaults to 50.',
|
|
599
604
|
required: false,
|
|
600
605
|
positional: false,
|
|
606
|
+
default: 50,
|
|
601
607
|
},
|
|
602
608
|
},
|
|
603
609
|
},
|
|
@@ -645,16 +651,18 @@ export const commands = {
|
|
|
645
651
|
pageIdx: {
|
|
646
652
|
name: 'pageIdx',
|
|
647
653
|
type: 'integer',
|
|
648
|
-
description: 'The page index
|
|
654
|
+
description: 'The zero-based page index. Defaults to 0 (the first page).',
|
|
649
655
|
required: false,
|
|
650
656
|
positional: false,
|
|
657
|
+
default: 0,
|
|
651
658
|
},
|
|
652
659
|
pageSize: {
|
|
653
660
|
name: 'pageSize',
|
|
654
661
|
type: 'integer',
|
|
655
|
-
description: 'The
|
|
662
|
+
description: 'The maximum number of items to return per page. Defaults to 50.',
|
|
656
663
|
required: false,
|
|
657
664
|
positional: false,
|
|
665
|
+
default: 50,
|
|
658
666
|
},
|
|
659
667
|
},
|
|
660
668
|
},
|
|
@@ -699,16 +707,18 @@ export const commands = {
|
|
|
699
707
|
pageIdx: {
|
|
700
708
|
name: 'pageIdx',
|
|
701
709
|
type: 'integer',
|
|
702
|
-
description: 'The page index
|
|
710
|
+
description: 'The zero-based page index. Defaults to 0 (the first page).',
|
|
703
711
|
required: false,
|
|
704
712
|
positional: false,
|
|
713
|
+
default: 0,
|
|
705
714
|
},
|
|
706
715
|
pageSize: {
|
|
707
716
|
name: 'pageSize',
|
|
708
717
|
type: 'integer',
|
|
709
|
-
description: 'The page
|
|
718
|
+
description: 'The maximum number of items to return per page. Defaults to 50.',
|
|
710
719
|
required: false,
|
|
711
720
|
positional: false,
|
|
721
|
+
default: 50,
|
|
712
722
|
},
|
|
713
723
|
maxNameLength: {
|
|
714
724
|
name: 'maxNameLength',
|
|
@@ -769,16 +779,18 @@ export const commands = {
|
|
|
769
779
|
pageIdx: {
|
|
770
780
|
name: 'pageIdx',
|
|
771
781
|
type: 'integer',
|
|
772
|
-
description: 'The page index
|
|
782
|
+
description: 'The zero-based page index. Defaults to 0 (the first page).',
|
|
773
783
|
required: false,
|
|
774
784
|
positional: false,
|
|
785
|
+
default: 0,
|
|
775
786
|
},
|
|
776
787
|
pageSize: {
|
|
777
788
|
name: 'pageSize',
|
|
778
789
|
type: 'integer',
|
|
779
|
-
description: 'The page
|
|
790
|
+
description: 'The maximum number of items to return per page. Defaults to 50.',
|
|
780
791
|
required: false,
|
|
781
792
|
positional: false,
|
|
793
|
+
default: 50,
|
|
782
794
|
},
|
|
783
795
|
},
|
|
784
796
|
},
|
|
@@ -837,16 +849,18 @@ export const commands = {
|
|
|
837
849
|
pageIdx: {
|
|
838
850
|
name: 'pageIdx',
|
|
839
851
|
type: 'integer',
|
|
840
|
-
description: 'The page index
|
|
852
|
+
description: 'The zero-based page index. Defaults to 0 (the first page).',
|
|
841
853
|
required: false,
|
|
842
854
|
positional: false,
|
|
855
|
+
default: 0,
|
|
843
856
|
},
|
|
844
857
|
pageSize: {
|
|
845
858
|
name: 'pageSize',
|
|
846
859
|
type: 'integer',
|
|
847
|
-
description: 'The page
|
|
860
|
+
description: 'The maximum number of items to return per page. Defaults to 50.',
|
|
848
861
|
required: false,
|
|
849
862
|
positional: false,
|
|
863
|
+
default: 50,
|
|
850
864
|
},
|
|
851
865
|
},
|
|
852
866
|
},
|
|
@@ -1153,7 +1167,7 @@ export const commands = {
|
|
|
1153
1167
|
pageIdx: {
|
|
1154
1168
|
name: 'pageIdx',
|
|
1155
1169
|
type: 'integer',
|
|
1156
|
-
description: 'Page number to return (0-based). When omitted, returns the first page.',
|
|
1170
|
+
description: 'Page number to return (0-based). When omitted, returns the first page. Ignored unless pageSize is set.',
|
|
1157
1171
|
required: false,
|
|
1158
1172
|
positional: false,
|
|
1159
1173
|
},
|
|
@@ -1183,7 +1197,7 @@ export const commands = {
|
|
|
1183
1197
|
serviceWorkerId: {
|
|
1184
1198
|
name: 'serviceWorkerId',
|
|
1185
1199
|
type: 'string',
|
|
1186
|
-
description: 'Filter messages
|
|
1200
|
+
description: 'Filter messages by the service worker ID shown by list_pages (sw-N).',
|
|
1187
1201
|
required: false,
|
|
1188
1202
|
positional: false,
|
|
1189
1203
|
},
|
|
@@ -1215,7 +1229,7 @@ export const commands = {
|
|
|
1215
1229
|
pageIdx: {
|
|
1216
1230
|
name: 'pageIdx',
|
|
1217
1231
|
type: 'integer',
|
|
1218
|
-
description: 'Page number to return (0-based). When omitted, returns the first page.',
|
|
1232
|
+
description: 'Page number to return (0-based). When omitted, returns the first page. Ignored unless pageSize is set.',
|
|
1219
1233
|
required: false,
|
|
1220
1234
|
positional: false,
|
|
1221
1235
|
},
|
|
@@ -1526,16 +1540,18 @@ export const commands = {
|
|
|
1526
1540
|
pageIdx: {
|
|
1527
1541
|
name: 'pageIdx',
|
|
1528
1542
|
type: 'integer',
|
|
1529
|
-
description: 'The page index
|
|
1543
|
+
description: 'The zero-based page index. Defaults to 0 (the first page).',
|
|
1530
1544
|
required: false,
|
|
1531
1545
|
positional: false,
|
|
1546
|
+
default: 0,
|
|
1532
1547
|
},
|
|
1533
1548
|
pageSize: {
|
|
1534
1549
|
name: 'pageSize',
|
|
1535
1550
|
type: 'integer',
|
|
1536
|
-
description: 'The page
|
|
1551
|
+
description: 'The maximum number of items to return per page. Defaults to 50.',
|
|
1537
1552
|
required: false,
|
|
1538
1553
|
positional: false,
|
|
1554
|
+
default: 50,
|
|
1539
1555
|
},
|
|
1540
1556
|
maxNameLength: {
|
|
1541
1557
|
name: 'maxNameLength',
|
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { DEFAULT_MAX_NAVIGATION_SAVED } from '../collectors/constants.js';
|
|
6
7
|
import os from 'node:os';
|
|
7
8
|
import path from 'node:path';
|
|
8
|
-
import { getCategoryOptions } from './category-options.js';
|
|
9
|
+
import { getCategoryOptions, } from './category-options.js';
|
|
9
10
|
import { getBrowserOptions } from './browser-options.js';
|
|
10
|
-
import { puppeteerOptions } from './puppeteer-options.js';
|
|
11
|
+
import { puppeteerOptions, } from './puppeteer-options.js';
|
|
11
12
|
import { toolOptions } from './tool-options.js';
|
|
12
13
|
export const DEFAULT_FILESYSTEM_ROOT = [os.tmpdir()];
|
|
14
|
+
// Each retained navigation can hold up to 1,000 network requests and 10,000
|
|
15
|
+
// console messages, so the history is capped to avoid running out of memory.
|
|
16
|
+
export const MAX_NAVIGATION_SAVED_LIMIT = 25;
|
|
13
17
|
export const mcpOptions = {
|
|
14
18
|
...getCategoryOptions(),
|
|
15
19
|
...getBrowserOptions(),
|
|
@@ -139,6 +143,22 @@ export const mcpOptions = {
|
|
|
139
143
|
describe: 'Whether to enable source maps in DevTools. Use --no-source-maps to disable.',
|
|
140
144
|
reloadable: true,
|
|
141
145
|
},
|
|
146
|
+
maxNavigationSaved: {
|
|
147
|
+
type: 'number',
|
|
148
|
+
default: DEFAULT_MAX_NAVIGATION_SAVED,
|
|
149
|
+
describe: `Number of navigations (including the current one) for which network requests and console messages are retained per page. Must be between 1 and ${MAX_NAVIGATION_SAVED_LIMIT}. For earlier navigations, request URLs, status codes, and request and response headers are retained, which is sufficient to trace redirect hops, but response bodies are generally no longer available.`,
|
|
150
|
+
coerce: (value) => {
|
|
151
|
+
if (value === undefined) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (!Number.isInteger(value) ||
|
|
155
|
+
value <= 0 ||
|
|
156
|
+
value > MAX_NAVIGATION_SAVED_LIMIT) {
|
|
157
|
+
throw new Error(`Invalid maxNavigationSaved ${value}. Expected an integer between 1 and ${MAX_NAVIGATION_SAVED_LIMIT}.`);
|
|
158
|
+
}
|
|
159
|
+
return value;
|
|
160
|
+
},
|
|
161
|
+
},
|
|
142
162
|
clearcutEndpoint: {
|
|
143
163
|
type: 'string',
|
|
144
164
|
hidden: true,
|
|
@@ -202,43 +222,43 @@ export const mcpOptions = {
|
|
|
202
222
|
return path.resolve(configPath);
|
|
203
223
|
},
|
|
204
224
|
},
|
|
225
|
+
watchConfig: {
|
|
226
|
+
type: 'boolean',
|
|
227
|
+
default: false,
|
|
228
|
+
describe: 'Watch the config file for changes and apply them without restarting. Tools (except --categoryExtensions) are enabled, disabled and updated on the fly; options used to launch or connect to the browser still require a restart.',
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
export const mcpOptionsForViaCli = {
|
|
232
|
+
...mcpOptions,
|
|
233
|
+
headless: {
|
|
234
|
+
...mcpOptions.headless,
|
|
235
|
+
default: true,
|
|
236
|
+
},
|
|
237
|
+
memoryDebugging: {
|
|
238
|
+
...mcpOptions.memoryDebugging,
|
|
239
|
+
default: true,
|
|
240
|
+
},
|
|
241
|
+
categoryExtensions: {
|
|
242
|
+
...mcpOptions.categoryExtensions,
|
|
243
|
+
defaultDescription: 'true unless autoConnect, browserUrl or wsEndpoint is set',
|
|
244
|
+
},
|
|
245
|
+
experimentalStructuredContent: {
|
|
246
|
+
...mcpOptions.experimentalStructuredContent,
|
|
247
|
+
default: true,
|
|
248
|
+
},
|
|
249
|
+
isolated: {
|
|
250
|
+
...mcpOptions.isolated,
|
|
251
|
+
description: 'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to true unless userDataDir is provided.',
|
|
252
|
+
defaultDescription: 'true unless userDataDir, autoConnect, browserUrl or wsEndpoint is set',
|
|
253
|
+
},
|
|
205
254
|
};
|
|
206
|
-
export function getMcpOptionsForViaCli() {
|
|
207
|
-
if (!('default' in mcpOptions.headless)) {
|
|
208
|
-
throw new Error('headless cli option unexpectedly does not have a default');
|
|
209
|
-
}
|
|
210
|
-
if (!('default' in mcpOptions.experimentalStructuredContent)) {
|
|
211
|
-
throw new Error('experimentalStructuredContent cli option unexpectedly does not have a default');
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
...mcpOptions,
|
|
215
|
-
headless: {
|
|
216
|
-
...mcpOptions.headless,
|
|
217
|
-
default: true,
|
|
218
|
-
},
|
|
219
|
-
memoryDebugging: {
|
|
220
|
-
...mcpOptions.memoryDebugging,
|
|
221
|
-
default: true,
|
|
222
|
-
},
|
|
223
|
-
categoryExtensions: {
|
|
224
|
-
...mcpOptions.categoryExtensions,
|
|
225
|
-
defaultDescription: 'true unless autoConnect, browserUrl or wsEndpoint is set',
|
|
226
|
-
},
|
|
227
|
-
experimentalStructuredContent: {
|
|
228
|
-
...mcpOptions.experimentalStructuredContent,
|
|
229
|
-
default: true,
|
|
230
|
-
},
|
|
231
|
-
isolated: {
|
|
232
|
-
...mcpOptions.isolated,
|
|
233
|
-
description: 'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to true unless userDataDir is provided.',
|
|
234
|
-
defaultDescription: 'true unless userDataDir, autoConnect, browserUrl or wsEndpoint is set',
|
|
235
|
-
},
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
255
|
export function getCliOptions() {
|
|
239
|
-
const options = withoutDefaults(
|
|
256
|
+
const options = withoutDefaults(mcpOptionsForViaCli);
|
|
240
257
|
// Missing CLI serialization.
|
|
241
258
|
delete options.viewport;
|
|
259
|
+
// The CLI is generated for the full mode with pageId routing, not slim mode.
|
|
260
|
+
delete options.slim;
|
|
261
|
+
delete options.pageIdRouting;
|
|
242
262
|
// Change the defaults for the CLI.
|
|
243
263
|
delete options.experimentalStructuredContent;
|
|
244
264
|
delete options.experimentalInteropTools;
|
|
@@ -332,6 +352,12 @@ export function withoutDefaults(options) {
|
|
|
332
352
|
}
|
|
333
353
|
return result;
|
|
334
354
|
}
|
|
355
|
+
export function stripYargsPositionalArgs(parsed) {
|
|
356
|
+
const copy = { ...parsed };
|
|
357
|
+
delete copy._;
|
|
358
|
+
delete copy.$0;
|
|
359
|
+
return copy;
|
|
360
|
+
}
|
|
335
361
|
export function isReloadableOption(name) {
|
|
336
362
|
const option = mcpOptions[name];
|
|
337
363
|
return option.reloadable === true;
|
|
@@ -37,7 +37,8 @@ export const puppeteerOptions = {
|
|
|
37
37
|
blockedUrlPattern: {
|
|
38
38
|
type: 'array',
|
|
39
39
|
string: true,
|
|
40
|
-
|
|
40
|
+
reloadable: true,
|
|
41
|
+
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); targets already open when patterns are updated via --watchConfig remain attached. Accepts an array of patterns. A pattern that uses a regexp group, a named group (`:name`), or a partial IPv4 wildcard (for example `(127\\.\\d+\\.\\d+\\.\\d+)`, `*://127.0.0.1::port/*`, or `*://127.0.0.*/*`) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*` wildcard instead. Patterns follow URL Pattern defaults: an omitted port matches only the scheme's default port (for example, `https://internal.corp/*` does not match `https://internal.corp:8443/`; use `https://internal.corp:*/*` to match any port), and the hostname must match exactly (a trailing-dot host such as `internal.corp.` is a different hostname).",
|
|
41
42
|
coerce: (arg) => {
|
|
42
43
|
if (arg === undefined || arg.length === 0) {
|
|
43
44
|
return undefined;
|
|
@@ -49,7 +50,8 @@ export const puppeteerOptions = {
|
|
|
49
50
|
allowedUrlPattern: {
|
|
50
51
|
type: 'array',
|
|
51
52
|
string: true,
|
|
52
|
-
|
|
53
|
+
reloadable: true,
|
|
54
|
+
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); targets already open when patterns are updated via --watchConfig remain attached. Accepts an array of patterns. A pattern that uses a regexp group, a named group (`:name`), or a partial IPv4 wildcard (for example `(127\\.\\d+\\.\\d+\\.\\d+)`, `*://127.0.0.1::port/*`, or `*://127.0.0.*/*`) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*` wildcard instead. Patterns follow URL Pattern defaults: an omitted port matches only the scheme's default port (for example, `https://internal.corp/*` does not match `https://internal.corp:8443/`; use `https://internal.corp:*/*` to match any port), and the hostname must match exactly (a trailing-dot host such as `internal.corp.` is a different hostname).",
|
|
53
55
|
coerce: (arg) => {
|
|
54
56
|
if (arg === undefined) {
|
|
55
57
|
return undefined;
|
|
@@ -7,9 +7,9 @@ import { spawn } from 'node:child_process';
|
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import net from 'node:net';
|
|
9
9
|
import path from 'node:path';
|
|
10
|
-
import { PipeTransport } from '../third_party/
|
|
10
|
+
import { PipeTransport } from '../third_party/cli.js';
|
|
11
11
|
import { getTempFilePath } from '../utils/files.js';
|
|
12
|
-
import { logger, puppeteerLogger } from '../utils/logger.js';
|
|
12
|
+
import { logger, puppeteerLogger, redactDaemonArgsForLogging, } from '../utils/logger.js';
|
|
13
13
|
import { DAEMON_SCRIPT_PATH, getDaemonPid, getSocketPath, getPidFilePath, isDaemonRunning, } from './utils.js';
|
|
14
14
|
const FILE_TIMEOUT = 10_000;
|
|
15
15
|
const READY_CHECK_INTERVAL = 100;
|
|
@@ -89,7 +89,7 @@ export async function startDaemon(mcpArgs = [], sessionId) {
|
|
|
89
89
|
}
|
|
90
90
|
fs.unlinkSync(pidFilePath);
|
|
91
91
|
}
|
|
92
|
-
logger?.('Starting daemon...', ...mcpArgs);
|
|
92
|
+
logger?.('Starting daemon...', ...redactDaemonArgsForLogging(mcpArgs));
|
|
93
93
|
const child = spawn(process.execPath, [DAEMON_SCRIPT_PATH, ...mcpArgs], {
|
|
94
94
|
detached: true,
|
|
95
95
|
stdio: 'ignore',
|
|
@@ -103,15 +103,19 @@ let server = null;
|
|
|
103
103
|
async function setupMCPServer() {
|
|
104
104
|
logger?.(`Starting Chrome DevTools MCP Server v${VERSION}`);
|
|
105
105
|
const configParser = new ConfigParser(VERSION);
|
|
106
|
-
const
|
|
106
|
+
const serverConfig = configParser.parseConfig();
|
|
107
|
+
const args = serverConfig.resolved;
|
|
107
108
|
const logFile = args.logFile ? saveLogsToFile(args.logFile) : undefined;
|
|
108
|
-
const browserManager = new BrowserManager(
|
|
109
|
+
const browserManager = new BrowserManager(serverConfig, {
|
|
109
110
|
logFile,
|
|
110
111
|
});
|
|
111
|
-
mcpServer = await McpServer.from(
|
|
112
|
+
mcpServer = await McpServer.from(serverConfig, {
|
|
112
113
|
browserManager,
|
|
113
114
|
logFile,
|
|
114
115
|
});
|
|
116
|
+
if (args.watchConfig) {
|
|
117
|
+
mcpServer.watchConfig();
|
|
118
|
+
}
|
|
115
119
|
ClearcutLogger.get()?.setClientName(DAEMON_CLIENT_NAME);
|
|
116
120
|
void ClearcutLogger.get()?.logDailyActiveIfNeeded();
|
|
117
121
|
void ClearcutLogger.get()?.logServerStart(computeFlagUsage(args, mcpOptions));
|
|
@@ -161,7 +161,8 @@ export function serializeArgs(options, argv) {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
else {
|
|
164
|
-
|
|
164
|
+
const serializedValue = typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
165
|
+
args.push(`--${kebabKey}=${serializedValue}`);
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
return args;
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
import { logger } from '../utils/logger.js';
|
|
7
7
|
const DEFAULT_DEBOUNCE_MS = 200;
|
|
8
8
|
/**
|
|
9
|
-
* Manages the
|
|
10
|
-
* and
|
|
9
|
+
* Manages the bridge between DevTools frontend comments and the MCP server.
|
|
10
|
+
* Comment events are debounced and delivered to callers that wait for them
|
|
11
|
+
* through `waitForCommentEvent`.
|
|
11
12
|
*/
|
|
12
13
|
export class DevToolsCommentBridge {
|
|
13
|
-
#onNotification;
|
|
14
14
|
#debounceMs;
|
|
15
15
|
#commentDebounceTimer;
|
|
16
16
|
#attachedPages = new Set();
|
|
17
|
+
#commentWaiters = new Set();
|
|
17
18
|
constructor(options) {
|
|
18
|
-
this.#onNotification = options?.onNotification;
|
|
19
19
|
this.#debounceMs = options?.debounceMs ?? DEFAULT_DEBOUNCE_MS;
|
|
20
20
|
}
|
|
21
21
|
isAttached(devtoolsPage) {
|
|
@@ -90,19 +90,42 @@ export class DevToolsCommentBridge {
|
|
|
90
90
|
return window.universe?.cd4aBridge?.getCommentThreads() ?? [];
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Resolves `true` on the next debounced comment event, or `false` when
|
|
95
|
+
* `timeoutMs` elapses or the bridge is disposed first.
|
|
96
|
+
*/
|
|
97
|
+
waitForCommentEvent(timeoutMs) {
|
|
98
|
+
return new Promise(resolve => {
|
|
99
|
+
const settle = (changed) => {
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
this.#commentWaiters.delete(settle);
|
|
102
|
+
resolve(changed);
|
|
103
|
+
};
|
|
104
|
+
const timer = setTimeout(() => {
|
|
105
|
+
settle(false);
|
|
106
|
+
}, timeoutMs);
|
|
107
|
+
this.#commentWaiters.add(settle);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
93
110
|
#handleCommentEvent() {
|
|
94
111
|
if (this.#commentDebounceTimer) {
|
|
95
112
|
clearTimeout(this.#commentDebounceTimer);
|
|
96
113
|
}
|
|
97
114
|
this.#commentDebounceTimer = setTimeout(() => {
|
|
98
|
-
this.#
|
|
115
|
+
this.#notifyCommentWaiters(true);
|
|
99
116
|
}, this.#debounceMs);
|
|
100
117
|
}
|
|
118
|
+
#notifyCommentWaiters(changed) {
|
|
119
|
+
for (const waiter of [...this.#commentWaiters]) {
|
|
120
|
+
waiter(changed);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
101
123
|
dispose() {
|
|
102
124
|
if (this.#commentDebounceTimer) {
|
|
103
125
|
clearTimeout(this.#commentDebounceTimer);
|
|
104
126
|
this.#commentDebounceTimer = undefined;
|
|
105
127
|
}
|
|
128
|
+
this.#notifyCommentWaiters(false);
|
|
106
129
|
for (const page of this.#attachedPages) {
|
|
107
130
|
try {
|
|
108
131
|
const result = page.evaluate(() => {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { DevTools } from '../third_party/index.js';
|
|
6
|
+
import { DevTools, } from '../third_party/index.js';
|
|
7
7
|
import { McpHostBindingAdapter } from './McpHostBindingAdapter.js';
|
|
8
8
|
/**
|
|
9
9
|
* A mock implementation of an issues manager that only implements the methods
|
|
@@ -153,14 +153,14 @@ export class SymbolizedError {
|
|
|
153
153
|
}
|
|
154
154
|
static async fromDetails(opts) {
|
|
155
155
|
const message = SymbolizedError.#getMessage(opts.details);
|
|
156
|
-
if (!opts.includeStackAndCause || !opts.devTools) {
|
|
156
|
+
if (!opts.includeStackAndCause || (!opts.devTools && !opts.session)) {
|
|
157
157
|
return new SymbolizedError(message, opts.resolvedStackTraceForTesting, opts.resolvedCauseForTesting);
|
|
158
158
|
}
|
|
159
159
|
let stackTrace;
|
|
160
160
|
if (opts.resolvedStackTraceForTesting) {
|
|
161
161
|
stackTrace = opts.resolvedStackTraceForTesting;
|
|
162
162
|
}
|
|
163
|
-
else if (opts.details.stackTrace) {
|
|
163
|
+
else if (opts.devTools && opts.details.stackTrace) {
|
|
164
164
|
try {
|
|
165
165
|
stackTrace = await createStackTrace(opts.devTools, opts.details.stackTrace, opts.targetId);
|
|
166
166
|
}
|
|
@@ -176,12 +176,13 @@ export class SymbolizedError {
|
|
|
176
176
|
}
|
|
177
177
|
else if (opts.details.exception) {
|
|
178
178
|
try {
|
|
179
|
-
const causeRemoteObj = await SymbolizedError.#lookupCause(opts.devTools, opts.details.exception, opts.targetId);
|
|
179
|
+
const causeRemoteObj = await SymbolizedError.#lookupCause(opts.devTools, opts.details.exception, opts.targetId, opts.session);
|
|
180
180
|
if (causeRemoteObj) {
|
|
181
181
|
cause = await SymbolizedError.fromError({
|
|
182
182
|
devTools: opts.devTools,
|
|
183
183
|
error: causeRemoteObj,
|
|
184
184
|
targetId: opts.targetId,
|
|
185
|
+
session: opts.session,
|
|
185
186
|
});
|
|
186
187
|
}
|
|
187
188
|
}
|
|
@@ -192,12 +193,13 @@ export class SymbolizedError {
|
|
|
192
193
|
return new SymbolizedError(message, stackTrace, cause);
|
|
193
194
|
}
|
|
194
195
|
static async fromError(opts) {
|
|
195
|
-
const details = await SymbolizedError.#getExceptionDetails(opts.devTools, opts.error, opts.targetId);
|
|
196
|
+
const details = await SymbolizedError.#getExceptionDetails(opts.devTools, opts.error, opts.targetId, opts.session);
|
|
196
197
|
if (details) {
|
|
197
198
|
return await SymbolizedError.fromDetails({
|
|
198
199
|
details,
|
|
199
200
|
devTools: opts.devTools,
|
|
200
201
|
targetId: opts.targetId,
|
|
202
|
+
session: opts.session,
|
|
201
203
|
includeStackAndCause: true,
|
|
202
204
|
});
|
|
203
205
|
}
|
|
@@ -207,18 +209,41 @@ export class SymbolizedError {
|
|
|
207
209
|
// For Runtime.exceptionThrown with a present exception object, `details.text` will be "Uncaught" and
|
|
208
210
|
// we have to manually parse out the error text from the exception description.
|
|
209
211
|
// In the case of Runtime.getExceptionDetails, `details.text` has the Error.message.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
+
// Unhandled promise rejections work the same way, with
|
|
213
|
+
// "Uncaught (in promise)" as `details.text` and the rejection reason as
|
|
214
|
+
// the exception.
|
|
215
|
+
if ((details.text === 'Uncaught' ||
|
|
216
|
+
details.text === 'Uncaught (in promise)') &&
|
|
217
|
+
details.exception) {
|
|
218
|
+
return (details.text +
|
|
219
|
+
' ' +
|
|
212
220
|
SymbolizedError.#getMessageFromException(details.exception));
|
|
213
221
|
}
|
|
214
222
|
return details.text;
|
|
215
223
|
}
|
|
216
224
|
static #getMessageFromException(error) {
|
|
217
|
-
|
|
225
|
+
if (error.description === undefined) {
|
|
226
|
+
// Primitive values, e.g. `Promise.reject('reason')`, have no description.
|
|
227
|
+
if (error.unserializableValue !== undefined) {
|
|
228
|
+
return error.unserializableValue;
|
|
229
|
+
}
|
|
230
|
+
return error.value === undefined ? '' : String(error.value);
|
|
231
|
+
}
|
|
232
|
+
const messageWithRest = error.description.split('\n at ', 2);
|
|
218
233
|
return messageWithRest[0] ?? '';
|
|
219
234
|
}
|
|
220
|
-
static async #getExceptionDetails(devTools, error, targetId) {
|
|
221
|
-
if (
|
|
235
|
+
static async #getExceptionDetails(devTools, error, targetId, session) {
|
|
236
|
+
if (error.type !== 'object' && error.subtype !== 'error') {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
if (session) {
|
|
240
|
+
if (!error.objectId) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
const { exceptionDetails } = await session.send('Runtime.getExceptionDetails', { errorObjectId: error.objectId });
|
|
244
|
+
return exceptionDetails ?? null;
|
|
245
|
+
}
|
|
246
|
+
if (!devTools) {
|
|
222
247
|
return null;
|
|
223
248
|
}
|
|
224
249
|
const targetManager = devTools.universe.context.get(DevTools.TargetManager);
|
|
@@ -228,8 +253,20 @@ export class SymbolizedError {
|
|
|
228
253
|
const model = target.model(DevTools.RuntimeModel);
|
|
229
254
|
return ((await model.getExceptionDetails(error.objectId)) ?? null);
|
|
230
255
|
}
|
|
231
|
-
static async #lookupCause(devTools, error, targetId) {
|
|
232
|
-
if (
|
|
256
|
+
static async #lookupCause(devTools, error, targetId, session) {
|
|
257
|
+
if (error.type !== 'object' && error.subtype !== 'error') {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
if (session) {
|
|
261
|
+
if (!error.objectId) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
const { result } = await session.send('Runtime.getProperties', {
|
|
265
|
+
objectId: error.objectId,
|
|
266
|
+
});
|
|
267
|
+
return result.find(prop => prop.name === 'cause')?.value ?? null;
|
|
268
|
+
}
|
|
269
|
+
if (!devTools) {
|
|
233
270
|
return null;
|
|
234
271
|
}
|
|
235
272
|
const targetManager = devTools.universe.context.get(DevTools.TargetManager);
|
|
@@ -6,6 +6,19 @@
|
|
|
6
6
|
import { createStackTraceForConsoleMessage, SymbolizedError, } from '../devtools/DevtoolsUtils.js';
|
|
7
7
|
import { UncaughtError } from '../collectors/PageCollector.js';
|
|
8
8
|
import * as DevTools from '../third_party/index.js';
|
|
9
|
+
import { formatRemoteObject } from './RemoteObjectFormatter.js';
|
|
10
|
+
// JSON.stringify prints Map, Set, functions and DOM nodes as `{}`, and throws
|
|
11
|
+
// on symbols and cyclic objects. Those are formatted from their preview.
|
|
12
|
+
function isJsonLike(remoteObject) {
|
|
13
|
+
if (remoteObject.type === 'object') {
|
|
14
|
+
return (remoteObject.subtype === undefined ||
|
|
15
|
+
remoteObject.subtype === 'array' ||
|
|
16
|
+
remoteObject.subtype === 'null');
|
|
17
|
+
}
|
|
18
|
+
return (remoteObject.type !== 'function' &&
|
|
19
|
+
remoteObject.type !== 'symbol' &&
|
|
20
|
+
remoteObject.type !== 'bigint');
|
|
21
|
+
}
|
|
9
22
|
export class ConsoleFormatter {
|
|
10
23
|
#id;
|
|
11
24
|
#type;
|
|
@@ -47,6 +60,7 @@ export class ConsoleFormatter {
|
|
|
47
60
|
devTools: options?.devTools,
|
|
48
61
|
details: msg.details,
|
|
49
62
|
targetId: msg.targetId,
|
|
63
|
+
session: msg.session,
|
|
50
64
|
includeStackAndCause: options?.fetchDetailedData || options?.fetchStackTrace,
|
|
51
65
|
resolvedStackTraceForTesting: options?.resolvedStackTraceForTesting,
|
|
52
66
|
resolvedCauseForTesting: options?.resolvedCauseForTesting,
|
|
@@ -78,7 +92,20 @@ export class ConsoleFormatter {
|
|
|
78
92
|
targetId: msg._targetId(),
|
|
79
93
|
});
|
|
80
94
|
}
|
|
81
|
-
|
|
95
|
+
if (!isJsonLike(remoteObject)) {
|
|
96
|
+
return formatRemoteObject(remoteObject);
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
return await arg.jsonValue();
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
// JSON can't represent the value (for example, a cyclic object)
|
|
103
|
+
// or the page is gone; the preview still describes it.
|
|
104
|
+
if (remoteObject.preview) {
|
|
105
|
+
return formatRemoteObject(remoteObject);
|
|
106
|
+
}
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
82
109
|
}
|
|
83
110
|
catch {
|
|
84
111
|
return `<error: Argument ${i} is no longer available>`;
|