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
package/build/src/McpResponse.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { CommentFormatter, } from './formatters/CommentFormatter.js';
|
|
7
7
|
import { ConsoleFormatter } from './formatters/ConsoleFormatter.js';
|
|
8
8
|
import { CssFormatter, resolveContainerQueries, } from './formatters/CssFormatter.js';
|
|
9
|
-
import { HeapSnapshotFormatter, isEdgeLike, isNodeLike, } from './formatters/HeapSnapshotFormatter.js';
|
|
9
|
+
import { collectRankedContexts, formatName, HeapSnapshotFormatter, isEdgeLike, isNodeLike, } from './formatters/HeapSnapshotFormatter.js';
|
|
10
10
|
import { IssueFormatter } from './formatters/IssueFormatter.js';
|
|
11
11
|
import { NetworkFormatter } from './formatters/NetworkFormatter.js';
|
|
12
12
|
import { SnapshotFormatter } from './formatters/SnapshotFormatter.js';
|
|
@@ -79,6 +79,9 @@ export class McpResponse {
|
|
|
79
79
|
this.#includeExtensionPages = value;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
+
setIncludeExtensionServiceWorkers(value) {
|
|
83
|
+
this.#includeExtensionServiceWorkers = value;
|
|
84
|
+
}
|
|
82
85
|
includeSnapshot(params) {
|
|
83
86
|
this.#snapshotParams = params ?? {
|
|
84
87
|
verbose: false,
|
|
@@ -210,9 +213,10 @@ export class McpResponse {
|
|
|
210
213
|
include: true,
|
|
211
214
|
aggregateData,
|
|
212
215
|
pagination: options,
|
|
216
|
+
formatOptions: options,
|
|
213
217
|
};
|
|
214
218
|
}
|
|
215
|
-
setHeapSnapshotStats(stats, staticData, nativeContextSizes, retainedByContextSummary) {
|
|
219
|
+
setHeapSnapshotStats(stats, staticData, nativeContextSizes, retainedByContextSummary, options) {
|
|
216
220
|
this.#heapSnapshotOptions = {
|
|
217
221
|
...this.#heapSnapshotOptions,
|
|
218
222
|
include: true,
|
|
@@ -220,6 +224,7 @@ export class McpResponse {
|
|
|
220
224
|
staticData,
|
|
221
225
|
nativeContextSizes,
|
|
222
226
|
retainedByContextSummary,
|
|
227
|
+
formatOptions: options,
|
|
223
228
|
};
|
|
224
229
|
}
|
|
225
230
|
setHeapSnapshotNodes(nodes, options) {
|
|
@@ -228,6 +233,7 @@ export class McpResponse {
|
|
|
228
233
|
include: true,
|
|
229
234
|
nodes,
|
|
230
235
|
pagination: options,
|
|
236
|
+
formatOptions: options,
|
|
231
237
|
};
|
|
232
238
|
}
|
|
233
239
|
setHeapSnapshotDuplicateStrings(duplicateStrings, options) {
|
|
@@ -236,41 +242,57 @@ export class McpResponse {
|
|
|
236
242
|
include: true,
|
|
237
243
|
duplicateStrings,
|
|
238
244
|
pagination: options,
|
|
245
|
+
formatOptions: options,
|
|
239
246
|
};
|
|
240
247
|
}
|
|
241
|
-
setHeapSnapshotRetainingPaths(retainingPaths) {
|
|
248
|
+
setHeapSnapshotRetainingPaths(retainingPaths, options) {
|
|
242
249
|
this.#heapSnapshotOptions = {
|
|
243
250
|
...this.#heapSnapshotOptions,
|
|
244
251
|
include: true,
|
|
245
252
|
retainingPaths,
|
|
253
|
+
formatOptions: options,
|
|
246
254
|
};
|
|
247
255
|
}
|
|
248
|
-
setHeapSnapshotDominators(dominators) {
|
|
256
|
+
setHeapSnapshotDominators(dominators, options) {
|
|
249
257
|
this.#heapSnapshotOptions = {
|
|
250
258
|
...this.#heapSnapshotOptions,
|
|
251
259
|
include: true,
|
|
252
260
|
dominators,
|
|
261
|
+
formatOptions: options,
|
|
253
262
|
};
|
|
254
263
|
}
|
|
255
|
-
setHeapSnapshotClassDiffs(
|
|
264
|
+
setHeapSnapshotClassDiffs(diff, options) {
|
|
256
265
|
this.#heapSnapshotOptions = {
|
|
257
266
|
...this.#heapSnapshotOptions,
|
|
258
267
|
include: true,
|
|
259
|
-
|
|
268
|
+
diff,
|
|
269
|
+
pagination: options,
|
|
270
|
+
formatOptions: options,
|
|
260
271
|
};
|
|
261
272
|
}
|
|
262
|
-
setHeapSnapshotDetailedClassDiff(detailedClassDiff) {
|
|
273
|
+
setHeapSnapshotDetailedClassDiff(detailedClassDiff, options) {
|
|
263
274
|
this.#heapSnapshotOptions = {
|
|
264
275
|
...this.#heapSnapshotOptions,
|
|
265
276
|
include: true,
|
|
266
277
|
detailedClassDiff,
|
|
278
|
+
formatOptions: options,
|
|
267
279
|
};
|
|
268
280
|
}
|
|
269
|
-
setHeapSnapshotObjectDetails(objectInfo) {
|
|
281
|
+
setHeapSnapshotObjectDetails(objectInfo, options) {
|
|
270
282
|
this.#heapSnapshotOptions = {
|
|
271
283
|
...this.#heapSnapshotOptions,
|
|
272
284
|
include: true,
|
|
273
285
|
objectInfo,
|
|
286
|
+
formatOptions: options,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
setHeapSnapshotContextAnalysis(contextAnalysis, options) {
|
|
290
|
+
this.#heapSnapshotOptions = {
|
|
291
|
+
...this.#heapSnapshotOptions,
|
|
292
|
+
include: true,
|
|
293
|
+
contextAnalysis,
|
|
294
|
+
contextAnalysisOptions: options,
|
|
295
|
+
formatOptions: options,
|
|
274
296
|
};
|
|
275
297
|
}
|
|
276
298
|
attachImage(value) {
|
|
@@ -307,9 +329,7 @@ export class McpResponse {
|
|
|
307
329
|
const result = await context.saveFile(new TextEncoder().encode(formatter.toString()), this.#snapshotParams.filePath, '.txt');
|
|
308
330
|
return result.filename;
|
|
309
331
|
}
|
|
310
|
-
|
|
311
|
-
return formatter;
|
|
312
|
-
}
|
|
332
|
+
return formatter;
|
|
313
333
|
}
|
|
314
334
|
async #handleAttachedNetworkRequest(context) {
|
|
315
335
|
if (!this.#attachedNetworkRequestId) {
|
|
@@ -346,7 +366,7 @@ export class McpResponse {
|
|
|
346
366
|
devTools: this.#page.devtoolsUniverse,
|
|
347
367
|
});
|
|
348
368
|
}
|
|
349
|
-
|
|
369
|
+
if (message instanceof DevTools.AggregatedIssue) {
|
|
350
370
|
const formatter = new IssueFormatter(message, {
|
|
351
371
|
id: consoleMessageStableId,
|
|
352
372
|
requestIdResolver: this.#page.resolveCdpRequestId.bind(this.#page),
|
|
@@ -357,9 +377,7 @@ export class McpResponse {
|
|
|
357
377
|
}
|
|
358
378
|
return formatter;
|
|
359
379
|
}
|
|
360
|
-
|
|
361
|
-
return undefined;
|
|
362
|
-
}
|
|
380
|
+
return undefined;
|
|
363
381
|
}
|
|
364
382
|
async #handleThirdPartyDevelopeTools() {
|
|
365
383
|
if (this.#args.categoryExperimentalThirdParty &&
|
|
@@ -459,7 +477,8 @@ export class McpResponse {
|
|
|
459
477
|
return undefined;
|
|
460
478
|
}
|
|
461
479
|
const page = this.#page;
|
|
462
|
-
|
|
480
|
+
const initialSnapshot = page?.textSnapshot;
|
|
481
|
+
const formatter = await CommentFormatter.from(comments, {
|
|
463
482
|
resolveBackendNodeId: page
|
|
464
483
|
? (id) => page.resolveBackendNodeId(id)
|
|
465
484
|
: undefined,
|
|
@@ -467,9 +486,19 @@ export class McpResponse {
|
|
|
467
486
|
? (id) => page.resolveCdpRequestId(id)
|
|
468
487
|
: undefined,
|
|
469
488
|
});
|
|
489
|
+
let commentsSnapshotRegenerated;
|
|
490
|
+
if (page?.textSnapshot && page.textSnapshot !== initialSnapshot) {
|
|
491
|
+
commentsSnapshotRegenerated = page.textSnapshot.verbose
|
|
492
|
+
? 'verbose'
|
|
493
|
+
: 'standard';
|
|
494
|
+
}
|
|
495
|
+
return { formatter, commentsSnapshotRegenerated };
|
|
470
496
|
}
|
|
471
497
|
async handle(context, dataFormat = 'default') {
|
|
472
|
-
|
|
498
|
+
if (this.#attachedWaitForResult?.openedPages && !this.#includePages) {
|
|
499
|
+
await context.createPagesSnapshot();
|
|
500
|
+
}
|
|
501
|
+
const [snapshot, detailedNetworkRequest, detailedConsoleMessage, thirdPartyDeveloperTools, webmcpTools, consoleMessages, networkRequests, commentsResult,] = await Promise.all([
|
|
473
502
|
this.#handleSnapshot(context),
|
|
474
503
|
this.#handleAttachedNetworkRequest(context),
|
|
475
504
|
this.#handleAttachedConsoleMessage(),
|
|
@@ -480,13 +509,13 @@ export class McpResponse {
|
|
|
480
509
|
this.#handleComments(),
|
|
481
510
|
]);
|
|
482
511
|
if (this.#includeExtensionServiceWorkers) {
|
|
483
|
-
|
|
512
|
+
context.createWorkersSnapshot();
|
|
484
513
|
}
|
|
485
514
|
let extensions;
|
|
486
515
|
if (this.#listExtensions) {
|
|
487
516
|
extensions = await context.listExtensions();
|
|
488
517
|
}
|
|
489
|
-
return this.format(context, {
|
|
518
|
+
return await this.format(context, {
|
|
490
519
|
detailedConsoleMessage,
|
|
491
520
|
consoleMessages,
|
|
492
521
|
snapshot,
|
|
@@ -498,7 +527,8 @@ export class McpResponse {
|
|
|
498
527
|
lighthouseResult: this.#attachedLighthouseResult,
|
|
499
528
|
thirdPartyDeveloperTools,
|
|
500
529
|
webmcpTools,
|
|
501
|
-
comments,
|
|
530
|
+
comments: commentsResult?.formatter,
|
|
531
|
+
commentsSnapshotRegenerated: commentsResult?.commentsSnapshotRegenerated,
|
|
502
532
|
errorMessage: this.#error?.message,
|
|
503
533
|
}, dataFormat);
|
|
504
534
|
}
|
|
@@ -549,10 +579,28 @@ export class McpResponse {
|
|
|
549
579
|
structuredContent.navigatedToUrl =
|
|
550
580
|
this.#attachedWaitForResult.navigatedToUrl;
|
|
551
581
|
}
|
|
582
|
+
if (this.#attachedWaitForResult.openedPages) {
|
|
583
|
+
const openedPages = this.#attachedWaitForResult.openedPages;
|
|
584
|
+
const openedMcpPages = context
|
|
585
|
+
.getPages()
|
|
586
|
+
.filter(mcpPage => openedPages.has(mcpPage.target));
|
|
587
|
+
if (openedMcpPages.length) {
|
|
588
|
+
const targetInfos = await context.getTargetInfos();
|
|
589
|
+
response.push('## Opened pages');
|
|
590
|
+
const structuredPages = [];
|
|
591
|
+
for (const mcpPage of openedMcpPages) {
|
|
592
|
+
const page = formatPage(mcpPage, context, targetInfos.get(mcpPage.targetId));
|
|
593
|
+
response.push(page.text);
|
|
594
|
+
structuredPages.push(page.structured);
|
|
595
|
+
}
|
|
596
|
+
structuredContent.openedPages = structuredPages;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
552
599
|
}
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
600
|
+
const page = this.#page;
|
|
601
|
+
const networkConditions = page?.networkConditions;
|
|
602
|
+
if (page && networkConditions) {
|
|
603
|
+
const timeout = page.pptrPage.getDefaultNavigationTimeout();
|
|
556
604
|
response.push(`Emulating network conditions: ${networkConditions}`);
|
|
557
605
|
response.push(`Default navigation timeout set to ${timeout} ms`);
|
|
558
606
|
structuredContent.networkConditions = networkConditions;
|
|
@@ -583,6 +631,21 @@ export class McpResponse {
|
|
|
583
631
|
response.push(`Emulating color scheme: ${colorScheme}`);
|
|
584
632
|
structuredContent.colorScheme = colorScheme;
|
|
585
633
|
}
|
|
634
|
+
const forcedColors = this.#page?.forcedColors;
|
|
635
|
+
if (forcedColors) {
|
|
636
|
+
response.push(`Emulating forced-colors: ${forcedColors}`);
|
|
637
|
+
structuredContent.forcedColors = forcedColors;
|
|
638
|
+
}
|
|
639
|
+
const prefersContrast = this.#page?.prefersContrast;
|
|
640
|
+
if (prefersContrast) {
|
|
641
|
+
response.push(`Emulating prefers-contrast: ${prefersContrast}`);
|
|
642
|
+
structuredContent.prefersContrast = prefersContrast;
|
|
643
|
+
}
|
|
644
|
+
const prefersReducedMotion = this.#page?.prefersReducedMotion;
|
|
645
|
+
if (prefersReducedMotion) {
|
|
646
|
+
response.push(`Emulating prefers-reduced-motion: ${prefersReducedMotion}`);
|
|
647
|
+
structuredContent.prefersReducedMotion = prefersReducedMotion;
|
|
648
|
+
}
|
|
586
649
|
const dialog = this.#page?.getDialog();
|
|
587
650
|
if (dialog) {
|
|
588
651
|
const defaultValueIfNeeded = dialog.type() === 'prompt'
|
|
@@ -600,7 +663,7 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
600
663
|
if (this.#includePages) {
|
|
601
664
|
const allPages = context.getPages();
|
|
602
665
|
const { regularPages, extensionPages } = allPages.reduce((acc, mcpPage) => {
|
|
603
|
-
if (mcpPage.
|
|
666
|
+
if (mcpPage.url().startsWith('chrome-extension://')) {
|
|
604
667
|
acc.extensionPages.push(mcpPage);
|
|
605
668
|
}
|
|
606
669
|
else {
|
|
@@ -619,6 +682,10 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
619
682
|
}
|
|
620
683
|
response.push(`Note: the previously selected page ${selectionFallback.wasClosed ? 'was closed' : 'is no longer listed'}.${selectedPageId !== undefined ? ` Page ${selectedPageId} is now selected.` : ''}`);
|
|
621
684
|
}
|
|
685
|
+
const targetInfos = regularPages.length ||
|
|
686
|
+
(this.#includeExtensionPages && extensionPages.length)
|
|
687
|
+
? await context.getTargetInfos()
|
|
688
|
+
: new Map();
|
|
622
689
|
if (regularPages.length) {
|
|
623
690
|
const parts = [`## Pages`];
|
|
624
691
|
const structuredPages = [];
|
|
@@ -627,12 +694,9 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
627
694
|
const contextLabel = isolatedContextName
|
|
628
695
|
? ` isolatedContext=${isolatedContextName}`
|
|
629
696
|
: '';
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
: mcpPage.pptrPage.url();
|
|
634
|
-
parts.push(`${mcpPage.id}: ${pageLabel}${context.isPageSelected(mcpPage) ? ' [selected]' : ''}${contextLabel}`);
|
|
635
|
-
structuredPages.push(createStructuredPage(mcpPage, context, title));
|
|
697
|
+
const page = formatPage(mcpPage, context, targetInfos.get(mcpPage.targetId));
|
|
698
|
+
parts.push(`${page.text}${context.isPageSelected(mcpPage) ? ' [selected]' : ''}${contextLabel}`);
|
|
699
|
+
structuredPages.push(page.structured);
|
|
636
700
|
}
|
|
637
701
|
response.push(...parts);
|
|
638
702
|
structuredContent.pages = structuredPages;
|
|
@@ -646,27 +710,25 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
646
710
|
const contextLabel = isolatedContextName
|
|
647
711
|
? ` isolatedContext=${isolatedContextName}`
|
|
648
712
|
: '';
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
: mcpPage.pptrPage.url();
|
|
653
|
-
response.push(`${mcpPage.id}: ${pageLabel}${context.isPageSelected(mcpPage) ? ' [selected]' : ''}${contextLabel}`);
|
|
654
|
-
structuredExtensionPages.push(createStructuredPage(mcpPage, context, title));
|
|
713
|
+
const page = formatPage(mcpPage, context, targetInfos.get(mcpPage.targetId));
|
|
714
|
+
response.push(`${page.text}${context.isPageSelected(mcpPage) ? ' [selected]' : ''}${contextLabel}`);
|
|
715
|
+
structuredExtensionPages.push(page.structured);
|
|
655
716
|
}
|
|
656
717
|
structuredContent.extensionPages = structuredExtensionPages;
|
|
657
718
|
}
|
|
658
719
|
}
|
|
659
720
|
}
|
|
660
721
|
if (this.#includeExtensionServiceWorkers) {
|
|
661
|
-
|
|
722
|
+
const extensionServiceWorkers = context
|
|
723
|
+
.getWorkers()
|
|
724
|
+
.filter(worker => worker.type === 'service_worker');
|
|
725
|
+
if (extensionServiceWorkers.length) {
|
|
662
726
|
response.push(`## Extension Service Workers`);
|
|
663
727
|
}
|
|
664
|
-
for (const extensionServiceWorker of
|
|
728
|
+
for (const extensionServiceWorker of extensionServiceWorkers) {
|
|
665
729
|
response.push(`${extensionServiceWorker.id}: ${extensionServiceWorker.url}`);
|
|
666
730
|
}
|
|
667
|
-
structuredContent.extensionServiceWorkers =
|
|
668
|
-
.getExtensionServiceWorkers()
|
|
669
|
-
.map(extensionServiceWorker => {
|
|
731
|
+
structuredContent.extensionServiceWorkers = extensionServiceWorkers.map(extensionServiceWorker => {
|
|
670
732
|
return {
|
|
671
733
|
id: extensionServiceWorker.id,
|
|
672
734
|
url: extensionServiceWorker.url,
|
|
@@ -705,19 +767,61 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
705
767
|
}
|
|
706
768
|
if (data.lighthouseResult) {
|
|
707
769
|
structuredContent.lighthouseResult = data.lighthouseResult;
|
|
708
|
-
const { summary, reports } = data.lighthouseResult;
|
|
709
|
-
response.push('## Lighthouse
|
|
770
|
+
const { summary, failedAudits, reports } = data.lighthouseResult;
|
|
771
|
+
response.push('## Lighthouse audit results');
|
|
710
772
|
response.push(`Mode: ${summary.mode}`);
|
|
711
773
|
response.push(`Device: ${summary.device}`);
|
|
712
774
|
response.push(`URL: ${summary.url}`);
|
|
713
|
-
response.push('### Category
|
|
775
|
+
response.push('### Category scores');
|
|
714
776
|
for (const score of summary.scores) {
|
|
715
|
-
|
|
777
|
+
// Lighthouse uses a null score for categories that could not be
|
|
778
|
+
// scored and renders scores as Math.round(score * 100).
|
|
779
|
+
const formattedScore = score.score === null ? 'n/a' : Math.round(score.score * 100);
|
|
780
|
+
response.push(`- ${score.title}: ${formattedScore} (${score.id})`);
|
|
716
781
|
}
|
|
717
|
-
response.push('### Audit
|
|
782
|
+
response.push('### Audit summary');
|
|
718
783
|
response.push(`Passed: ${summary.audits.passed}`);
|
|
719
784
|
response.push(`Failed: ${summary.audits.failed}`);
|
|
720
|
-
response.push(`Total
|
|
785
|
+
response.push(`Total timing: ${summary.timing.total}ms`);
|
|
786
|
+
if (failedAudits.length) {
|
|
787
|
+
response.push('### Failed audits');
|
|
788
|
+
for (const audit of failedAudits) {
|
|
789
|
+
const categories = audit.categories.length
|
|
790
|
+
? ` [${audit.categories.join(', ')}]`
|
|
791
|
+
: '';
|
|
792
|
+
const displayValue = audit.displayValue
|
|
793
|
+
? ` (${audit.displayValue})`
|
|
794
|
+
: '';
|
|
795
|
+
response.push(`- ${audit.id}${categories}: ${audit.title}${displayValue} (score: ${audit.score})`);
|
|
796
|
+
if (audit.description) {
|
|
797
|
+
response.push(` ${collapseWhitespace(audit.description)}`);
|
|
798
|
+
}
|
|
799
|
+
if (audit.totalNodes) {
|
|
800
|
+
const shown = audit.totalNodes > audit.nodes.length
|
|
801
|
+
? `, showing ${audit.nodes.length}`
|
|
802
|
+
: '';
|
|
803
|
+
response.push(` Nodes (${audit.totalNodes}${shown}):`);
|
|
804
|
+
}
|
|
805
|
+
for (const node of audit.nodes) {
|
|
806
|
+
// Values are JSON-encoded so that quotes or spaces within them
|
|
807
|
+
// cannot be confused with the `key=value` delimiters.
|
|
808
|
+
const parts = [];
|
|
809
|
+
if (node.selector) {
|
|
810
|
+
parts.push(`selector=${JSON.stringify(node.selector)}`);
|
|
811
|
+
}
|
|
812
|
+
if (node.nodeLabel) {
|
|
813
|
+
parts.push(`label=${JSON.stringify(collapseWhitespace(node.nodeLabel))}`);
|
|
814
|
+
}
|
|
815
|
+
if (node.snippet) {
|
|
816
|
+
parts.push(`snippet=${JSON.stringify(collapseWhitespace(node.snippet))}`);
|
|
817
|
+
}
|
|
818
|
+
response.push(` - ${parts.join(' ')}`);
|
|
819
|
+
if (node.explanation) {
|
|
820
|
+
response.push(` ${collapseWhitespace(node.explanation)}`);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}
|
|
721
825
|
response.push('### Reports');
|
|
722
826
|
for (const report of reports) {
|
|
723
827
|
response.push(`- ${report}`);
|
|
@@ -738,6 +842,7 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
738
842
|
}
|
|
739
843
|
if (this.#heapSnapshotOptions?.include) {
|
|
740
844
|
response.push('## Heap Snapshot Data');
|
|
845
|
+
const formatOptions = this.#heapSnapshotOptions.formatOptions ?? {};
|
|
741
846
|
const stats = this.#heapSnapshotOptions.stats;
|
|
742
847
|
const staticData = this.#heapSnapshotOptions.staticData;
|
|
743
848
|
if (stats) {
|
|
@@ -753,7 +858,7 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
753
858
|
const nativeContextSizes = this.#heapSnapshotOptions.nativeContextSizes;
|
|
754
859
|
if (nativeContextSizes) {
|
|
755
860
|
response.push('### Native Contexts');
|
|
756
|
-
response.push(HeapSnapshotFormatter.formatNativeContextSizes(nativeContextSizes));
|
|
861
|
+
response.push(HeapSnapshotFormatter.formatNativeContextSizes(nativeContextSizes, formatOptions));
|
|
757
862
|
structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
|
|
758
863
|
structuredContent.heapSnapshot.nativeContextSizes = nativeContextSizes;
|
|
759
864
|
}
|
|
@@ -767,8 +872,7 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
767
872
|
}
|
|
768
873
|
const aggregateData = this.#heapSnapshotOptions.aggregateData;
|
|
769
874
|
if (aggregateData) {
|
|
770
|
-
const
|
|
771
|
-
const paginationData = this.#dataWithPagination(sortedEntries, this.#heapSnapshotOptions.pagination);
|
|
875
|
+
const paginationData = this.#dataWithPagination(aggregateData.aggregates, this.#heapSnapshotOptions.pagination);
|
|
772
876
|
response.push(`Objects: ${aggregateData.objectCount}`);
|
|
773
877
|
response.push(`Total shallow size: ${formatBytesToKb(aggregateData.totalSelfSize)}`);
|
|
774
878
|
structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
|
|
@@ -778,12 +882,13 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
778
882
|
};
|
|
779
883
|
structuredContent.pagination = paginationData.pagination;
|
|
780
884
|
response.push(...paginationData.info);
|
|
781
|
-
|
|
782
|
-
const formatter = new HeapSnapshotFormatter(paginatedRecord);
|
|
783
|
-
structuredContent.heapSnapshotData = formatter.toJSON();
|
|
885
|
+
structuredContent.heapSnapshotAggregates = paginationData.items;
|
|
784
886
|
response.push(compactEncode
|
|
785
|
-
? compactEncode(
|
|
786
|
-
|
|
887
|
+
? compactEncode(paginationData.items.map(aggregate => ({
|
|
888
|
+
...aggregate,
|
|
889
|
+
className: formatName(aggregate.className, formatOptions),
|
|
890
|
+
})))
|
|
891
|
+
: HeapSnapshotFormatter.formatAggregates(paginationData.items, formatOptions));
|
|
787
892
|
}
|
|
788
893
|
const nodes = this.#heapSnapshotOptions.nodes;
|
|
789
894
|
if (nodes) {
|
|
@@ -800,7 +905,7 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
800
905
|
}
|
|
801
906
|
}
|
|
802
907
|
const paginationData = this.#dataWithPagination(items, this.#heapSnapshotOptions.pagination);
|
|
803
|
-
response.push(HeapSnapshotFormatter.formatNodes(paginationData.items));
|
|
908
|
+
response.push(HeapSnapshotFormatter.formatNodes(paginationData.items, formatOptions));
|
|
804
909
|
structuredContent.pagination = paginationData.pagination;
|
|
805
910
|
response.push(...paginationData.info);
|
|
806
911
|
structuredContent.heapSnapshotNodes = paginationData.items;
|
|
@@ -813,7 +918,7 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
813
918
|
response.push('No retaining paths found.');
|
|
814
919
|
}
|
|
815
920
|
else {
|
|
816
|
-
response.push(HeapSnapshotFormatter.formatRetainingPaths(paths));
|
|
921
|
+
response.push(HeapSnapshotFormatter.formatRetainingPaths(paths, formatOptions));
|
|
817
922
|
}
|
|
818
923
|
const reached = Object.entries(limitsReached)
|
|
819
924
|
.filter(([, hit]) => hit)
|
|
@@ -831,24 +936,36 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
831
936
|
response.push('No dominators found.');
|
|
832
937
|
}
|
|
833
938
|
else {
|
|
834
|
-
response.push(HeapSnapshotFormatter.formatDominators(dominators));
|
|
939
|
+
response.push(HeapSnapshotFormatter.formatDominators(dominators, formatOptions));
|
|
835
940
|
}
|
|
836
941
|
structuredContent.heapSnapshotDominators = dominators;
|
|
837
942
|
}
|
|
838
|
-
const
|
|
839
|
-
if (
|
|
943
|
+
const diff = this.#heapSnapshotOptions.diff;
|
|
944
|
+
if (diff) {
|
|
840
945
|
response.push('### Heap Snapshot Diff');
|
|
946
|
+
response.push(HeapSnapshotFormatter.formatDiffTotals(diff.totals));
|
|
947
|
+
structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
|
|
948
|
+
structuredContent.heapSnapshot.classDiffStats = diff.totals;
|
|
949
|
+
const paginationData = this.#dataWithPagination(diff.classDiffs, this.#heapSnapshotOptions.pagination);
|
|
950
|
+
structuredContent.pagination = paginationData.pagination;
|
|
951
|
+
response.push(...paginationData.info);
|
|
841
952
|
response.push(compactEncode
|
|
842
|
-
? compactEncode(
|
|
843
|
-
|
|
844
|
-
|
|
953
|
+
? compactEncode(paginationData.items.map(diff => ({
|
|
954
|
+
...diff,
|
|
955
|
+
className: formatName(diff.className, formatOptions),
|
|
956
|
+
})))
|
|
957
|
+
: HeapSnapshotFormatter.formatDiffSummary(paginationData.items, formatOptions));
|
|
958
|
+
structuredContent.heapSnapshotClassDiffs = paginationData.items;
|
|
845
959
|
}
|
|
846
960
|
const detailedClassDiff = this.#heapSnapshotOptions.detailedClassDiff;
|
|
847
961
|
if (detailedClassDiff) {
|
|
848
962
|
response.push('### Heap Snapshot Detailed Diff');
|
|
849
963
|
response.push(compactEncode
|
|
850
|
-
? compactEncode(
|
|
851
|
-
|
|
964
|
+
? compactEncode({
|
|
965
|
+
...detailedClassDiff,
|
|
966
|
+
className: formatName(detailedClassDiff.className, formatOptions),
|
|
967
|
+
})
|
|
968
|
+
: HeapSnapshotFormatter.formatDiffDetails(detailedClassDiff, formatOptions));
|
|
852
969
|
structuredContent.heapSnapshotDetailedClassDiff = detailedClassDiff;
|
|
853
970
|
}
|
|
854
971
|
const duplicateStrings = this.#heapSnapshotOptions.duplicateStrings;
|
|
@@ -857,18 +974,47 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
857
974
|
const paginationData = this.#dataWithPagination(duplicateStrings, this.#heapSnapshotOptions.pagination);
|
|
858
975
|
structuredContent.pagination = paginationData.pagination;
|
|
859
976
|
response.push(...paginationData.info);
|
|
860
|
-
const formatted = HeapSnapshotFormatter.formatDuplicateStrings(paginationData.items);
|
|
977
|
+
const formatted = HeapSnapshotFormatter.formatDuplicateStrings(paginationData.items, formatOptions);
|
|
861
978
|
response.push(formatted);
|
|
862
979
|
structuredContent.heapSnapshotDuplicateStrings = paginationData.items;
|
|
863
980
|
}
|
|
864
981
|
const objectInfo = this.#heapSnapshotOptions.objectInfo;
|
|
865
982
|
if (objectInfo) {
|
|
866
983
|
response.push('### Object Details');
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
984
|
+
if (compactEncode) {
|
|
985
|
+
response.push(compactEncode({
|
|
986
|
+
...objectInfo,
|
|
987
|
+
name: formatName(objectInfo.name, formatOptions),
|
|
988
|
+
}));
|
|
989
|
+
}
|
|
990
|
+
else {
|
|
991
|
+
response.push(HeapSnapshotFormatter.formatObjectInfo(objectInfo, formatOptions));
|
|
992
|
+
}
|
|
870
993
|
structuredContent.heapSnapshotObjectDetails = objectInfo;
|
|
871
994
|
}
|
|
995
|
+
const contextAnalysis = this.#heapSnapshotOptions.contextAnalysis;
|
|
996
|
+
if (contextAnalysis) {
|
|
997
|
+
const contextAnalysisOptions = this.#heapSnapshotOptions.contextAnalysisOptions;
|
|
998
|
+
const rankedContexts = collectRankedContexts(contextAnalysis, {
|
|
999
|
+
retainedSize: contextAnalysisOptions?.retainedSize,
|
|
1000
|
+
scopeInfoNodeId: contextAnalysisOptions?.scopeInfoNodeId,
|
|
1001
|
+
});
|
|
1002
|
+
const paginationData = this.#dataWithPagination(rankedContexts, {
|
|
1003
|
+
pageIdx: contextAnalysisOptions?.pageIdx ?? 0,
|
|
1004
|
+
pageSize: contextAnalysisOptions?.pageSize,
|
|
1005
|
+
});
|
|
1006
|
+
const report = {
|
|
1007
|
+
contexts: paginationData.items,
|
|
1008
|
+
scriptsWithoutScopes: contextAnalysis.scriptsWithoutScopes,
|
|
1009
|
+
};
|
|
1010
|
+
response.push('### Context Analysis');
|
|
1011
|
+
structuredContent.pagination = paginationData.pagination;
|
|
1012
|
+
response.push(...paginationData.info);
|
|
1013
|
+
response.push(compactEncode
|
|
1014
|
+
? compactEncode(report)
|
|
1015
|
+
: HeapSnapshotFormatter.formatContextAnalysis(report, formatOptions));
|
|
1016
|
+
structuredContent.heapSnapshotContextAnalysis = report;
|
|
1017
|
+
}
|
|
872
1018
|
}
|
|
873
1019
|
if (data.detailedNetworkRequest) {
|
|
874
1020
|
response.push(data.detailedNetworkRequest.toStringDetailed());
|
|
@@ -976,6 +1122,11 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
976
1122
|
const commentsJson = data.comments.toJSON();
|
|
977
1123
|
structuredContent.comments = commentsJson;
|
|
978
1124
|
response.push(compactEncode ? compactEncode(commentsJson) : data.comments.toString());
|
|
1125
|
+
if (data.commentsSnapshotRegenerated) {
|
|
1126
|
+
response.push(`Note: DevTools comments regenerated the ${data.commentsSnapshotRegenerated} text snapshot.`);
|
|
1127
|
+
structuredContent.commentsSnapshotRegenerated =
|
|
1128
|
+
data.commentsSnapshotRegenerated;
|
|
1129
|
+
}
|
|
979
1130
|
}
|
|
980
1131
|
if (this.#cssStylesData) {
|
|
981
1132
|
const resolveUid = (backendNodeId) => this.#page?.textSnapshot?.resolveCdpElementId(backendNodeId);
|
|
@@ -1030,7 +1181,8 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
|
|
|
1030
1181
|
response.push('Invalid page number provided. Showing first page.');
|
|
1031
1182
|
}
|
|
1032
1183
|
const { startIndex, endIndex, currentPage, totalPages } = paginationResult;
|
|
1033
|
-
|
|
1184
|
+
const displayStartIndex = data.length === 0 ? 0 : startIndex + 1;
|
|
1185
|
+
response.push(`Showing ${displayStartIndex}-${endIndex} of ${data.length} (Page ${currentPage + 1} of ${totalPages}).`);
|
|
1034
1186
|
if (pagination) {
|
|
1035
1187
|
if (paginationResult.hasNextPage) {
|
|
1036
1188
|
response.push(`Next page: ${currentPage + 1}`);
|
|
@@ -1063,18 +1215,24 @@ function truncateTitle(title, maxLength = 50) {
|
|
|
1063
1215
|
}
|
|
1064
1216
|
return title.slice(0, maxLength - 3) + '...';
|
|
1065
1217
|
}
|
|
1066
|
-
|
|
1067
|
-
return
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1218
|
+
const collapseWhitespace = (value) => {
|
|
1219
|
+
return value.replace(/\s+/g, ' ').trim();
|
|
1220
|
+
};
|
|
1221
|
+
function formatPage(mcpPage, context, targetInfo) {
|
|
1222
|
+
const title = mcpPage.getTitle(targetInfo);
|
|
1223
|
+
const url = mcpPage.url();
|
|
1224
|
+
const pageLabel = title ? `${truncateTitle(title)} (${url})` : url;
|
|
1225
|
+
return {
|
|
1226
|
+
text: `${mcpPage.id}: ${pageLabel}`,
|
|
1227
|
+
structured: createStructuredPage(mcpPage, context, title),
|
|
1228
|
+
};
|
|
1071
1229
|
}
|
|
1072
1230
|
function createStructuredPage(mcpPage, context, rawTitle) {
|
|
1073
1231
|
const isolatedContextName = mcpPage.isolatedContextName;
|
|
1074
1232
|
const title = truncateTitle(rawTitle);
|
|
1075
1233
|
const entry = {
|
|
1076
1234
|
id: mcpPage.id,
|
|
1077
|
-
url: mcpPage.
|
|
1235
|
+
url: mcpPage.url(),
|
|
1078
1236
|
title,
|
|
1079
1237
|
selected: context.isPageSelected(mcpPage),
|
|
1080
1238
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Short id prefix that labels a worker's type in its id, e.g. `sw-1` for a
|
|
8
|
+
* service worker. The numeric part comes from a single shared counter, so the
|
|
9
|
+
* prefix is a readable type tag rather than a per-type sequence.
|
|
10
|
+
*/
|
|
11
|
+
const WORKER_ID_PREFIX = {
|
|
12
|
+
service_worker: 'sw',
|
|
13
|
+
dedicated_worker: 'dw',
|
|
14
|
+
shared_worker: 'shw',
|
|
15
|
+
};
|
|
16
|
+
export function workerIdPrefix(type) {
|
|
17
|
+
return WORKER_ID_PREFIX[type];
|
|
18
|
+
}
|
|
19
|
+
// Single shared counter across worker types. Ids are not reused across
|
|
20
|
+
// reconnects, mirroring the page id counter in McpContext; the type prefix is
|
|
21
|
+
// what distinguishes the kinds, not a per-type sequence.
|
|
22
|
+
let nextWorkerId = 1;
|
|
23
|
+
/**
|
|
24
|
+
* Wraps a Puppeteer worker {@link Target}, mirroring {@link McpPage}: it owns the
|
|
25
|
+
* target and the stable id assigned to it and lazily resolves the underlying
|
|
26
|
+
* {@link WebWorker}. Generalizes the former plain `ExtensionServiceWorker` type so
|
|
27
|
+
* dedicated and service workers share a single representation.
|
|
28
|
+
*/
|
|
29
|
+
export class McpWorker {
|
|
30
|
+
id;
|
|
31
|
+
type;
|
|
32
|
+
#target;
|
|
33
|
+
constructor(id, type, target) {
|
|
34
|
+
this.id = id;
|
|
35
|
+
this.type = type;
|
|
36
|
+
this.#target = target;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a worker with a freshly minted id derived from its type (e.g.
|
|
40
|
+
* `sw-1`). Keeps id composition in one place so callers only supply the type.
|
|
41
|
+
*/
|
|
42
|
+
static create(type, target) {
|
|
43
|
+
return new McpWorker(`${workerIdPrefix(type)}-${nextWorkerId++}`, type, target);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resets the shared id counter. For tests only, mirroring
|
|
47
|
+
* McpContext.resetPageIdsForTesting().
|
|
48
|
+
*/
|
|
49
|
+
static resetIdsForTesting() {
|
|
50
|
+
nextWorkerId = 1;
|
|
51
|
+
}
|
|
52
|
+
get target() {
|
|
53
|
+
return this.#target;
|
|
54
|
+
}
|
|
55
|
+
get url() {
|
|
56
|
+
return this.#target.url();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolves the worker's execution context, or `undefined` when the target
|
|
60
|
+
* does not expose one (e.g. it closed before the session attached).
|
|
61
|
+
*/
|
|
62
|
+
async worker() {
|
|
63
|
+
return (await this.#target.worker()) ?? undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=McpWorker.js.map
|