|
6 | 6 |
|
7 | 7 | import type {ParsedArguments} from './bin/chrome-devtools-mcp-cli-options.js'; |
8 | 8 | import {ConsoleFormatter} from './formatters/ConsoleFormatter.js'; |
| 9 | +import {HeapSnapshotFormatter} from './formatters/HeapSnapshotFormatter.js'; |
9 | 10 | import {IssueFormatter} from './formatters/IssueFormatter.js'; |
10 | 11 | import {NetworkFormatter} from './formatters/NetworkFormatter.js'; |
11 | 12 | import {SnapshotFormatter} from './formatters/SnapshotFormatter.js'; |
@@ -166,6 +167,14 @@ export class McpResponse implements Response { |
166 | 167 | #attachedLighthouseResult?: LighthouseData; |
167 | 168 | #textResponseLines: string[] = []; |
168 | 169 | #images: ImageContentData[] = []; |
| 170 | + #heapSnapshotOptions?: { |
| 171 | + include: boolean; |
| 172 | + aggregates: Record< |
| 173 | + string, |
| 174 | + DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo |
| 175 | + >; |
| 176 | + pagination?: PaginationOptions; |
| 177 | + }; |
169 | 178 | #networkRequestsOptions?: { |
170 | 179 | include: boolean; |
171 | 180 | pagination?: PaginationOptions; |
@@ -358,6 +367,20 @@ export class McpResponse implements Response { |
358 | 367 | this.#textResponseLines.push(value); |
359 | 368 | } |
360 | 369 |
|
| 370 | + setHeapSnapshot( |
| 371 | + aggregates: Record< |
| 372 | + string, |
| 373 | + DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo |
| 374 | + >, |
| 375 | + options?: PaginationOptions, |
| 376 | + ) { |
| 377 | + this.#heapSnapshotOptions = { |
| 378 | + include: true, |
| 379 | + aggregates, |
| 380 | + pagination: options, |
| 381 | + }; |
| 382 | + } |
| 383 | + |
361 | 384 | attachImage(value: ImageContentData): void { |
362 | 385 | this.#images.push(value); |
363 | 386 | } |
@@ -638,6 +661,7 @@ export class McpResponse implements Response { |
638 | 661 | }; |
639 | 662 | pages?: object[]; |
640 | 663 | pagination?: object; |
| 664 | + heapSnapshot?: object[]; |
641 | 665 | extensionServiceWorkers?: object[]; |
642 | 666 | extensionPages?: object[]; |
643 | 667 | } = {}; |
@@ -834,6 +858,26 @@ Call ${handleDialog.name} to handle it before continuing.`); |
834 | 858 | } |
835 | 859 | } |
836 | 860 |
|
| 861 | + if (this.#heapSnapshotOptions?.include) { |
| 862 | + const aggregates = this.#heapSnapshotOptions.aggregates; |
| 863 | + const entries = Object.entries(aggregates); |
| 864 | + const sortedEntries = entries.sort((a, b) => b[1].self - a[1].self); |
| 865 | + |
| 866 | + const paginationData = this.#dataWithPagination( |
| 867 | + sortedEntries, |
| 868 | + this.#heapSnapshotOptions.pagination, |
| 869 | + ); |
| 870 | + |
| 871 | + structuredContent.pagination = paginationData.pagination; |
| 872 | + response.push(...paginationData.info); |
| 873 | + |
| 874 | + const paginatedRecord = Object.fromEntries(paginationData.items); |
| 875 | + const formatter = new HeapSnapshotFormatter(paginatedRecord); |
| 876 | + |
| 877 | + response.push(formatter.toString()); |
| 878 | + structuredContent.heapSnapshot = formatter.toJSON(); |
| 879 | + } |
| 880 | + |
837 | 881 | if (data.detailedNetworkRequest) { |
838 | 882 | response.push(data.detailedNetworkRequest.toStringDetailed()); |
839 | 883 | structuredContent.networkRequest = |
|
0 commit comments