chrome-devtools-mcp 1.7.0 → 1.8.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 +48 -14
- package/build/src/McpContext.js +60 -24
- package/build/src/McpPage.js +5 -3
- package/build/src/McpResponse.js +22 -4
- package/build/src/ToolHandler.js +66 -12
- package/build/src/bin/chrome-devtools-mcp-main.js +2 -2
- package/build/src/bin/chrome-devtools.js +29 -30
- package/build/src/browser.js +3 -1
- package/build/src/{PageCollector.js → collectors/PageCollector.js} +7 -7
- package/build/src/{ServiceWorkerCollector.js → collectors/ServiceWorkerCollector.js} +1 -1
- package/build/src/{bin/chrome-devtools-cli-options.js → config/cli-options.js} +378 -23
- package/build/src/{bin/chrome-devtools-mcp-cli-options.js → config/mcp-options.js} +73 -8
- package/build/src/daemon/client.js +11 -2
- package/build/src/daemon/daemon.js +2 -2
- package/build/src/devtools/DevtoolsUtils.js +2 -14
- package/build/src/formatters/ConsoleFormatter.js +43 -10
- package/build/src/formatters/HeapSnapshotFormatter.js +10 -2
- package/build/src/formatters/IssueFormatter.js +1 -1
- package/build/src/formatters/NetworkFormatter.js +7 -7
- package/build/src/index.js +33 -5
- package/build/src/{HeapSnapshotManager.js → processors/HeapSnapshotManager.js} +21 -5
- package/build/src/{trace-processing/parse.js → processors/PerformanceTrace.js} +1 -1
- package/build/src/telemetry/ClearcutLogger.js +13 -1
- package/build/src/telemetry/flagUtils.js +4 -3
- package/build/src/telemetry/types.js +4 -0
- package/build/src/third_party/THIRD_PARTY_NOTICES +6 -63
- package/build/src/third_party/bundled-packages.json +4 -4
- package/build/src/third_party/devtools-heap-snapshot-worker.js +274 -42
- package/build/src/third_party/index.js +35378 -35538
- package/build/src/third_party/issue-descriptions/connectionAllowlistEmbeddingRequirementNotSatisfied.md +26 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistIFrameAttributeLoosensEmbeddingRequirement.md +19 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowConnectionAllowlistFrom.md +21 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsBlockedByConnectionAllowlist.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestConfigBlockedByConnectionAllowlist.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenBlockedByConnectionAllowlist.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestWellKnownBlockedByConnectionAllowlist.md +1 -0
- package/build/src/tools/categories.js +3 -0
- package/build/src/tools/console.js +9 -3
- package/build/src/tools/emulation.js +2 -2
- package/build/src/tools/extensions.js +7 -5
- package/build/src/tools/input.js +26 -16
- package/build/src/tools/lighthouse.js +3 -1
- package/build/src/tools/memory.js +112 -16
- package/build/src/tools/network.js +6 -3
- package/build/src/tools/pages.js +12 -16
- package/build/src/tools/performance.js +15 -25
- package/build/src/tools/pwa.js +128 -0
- package/build/src/tools/screencast.js +6 -4
- package/build/src/tools/screenshot.js +42 -9
- package/build/src/tools/script.js +28 -8
- package/build/src/tools/slim/tools.js +3 -3
- package/build/src/tools/snapshot.js +5 -3
- package/build/src/tools/thirdPartyDeveloper.js +2 -2
- package/build/src/tools/tools.js +2 -0
- package/build/src/tools/webmcp.js +2 -2
- package/build/src/{WaitForHelper.js → utils/WaitForHelper.js} +63 -38
- package/build/src/utils/bytes.js +105 -0
- package/build/src/utils/logger.js +25 -11
- package/build/src/version.js +1 -1
- package/package.json +20 -12
- package/skills/a11y-debugging/SKILL.md +2 -0
- package/skills/chrome-devtools/SKILL.md +5 -4
- package/skills/chrome-devtools-cli/SKILL.md +109 -64
- package/skills/debug-optimize-lcp/SKILL.md +9 -9
- package/skills/memory-leak-debugging/SKILL.md +2 -2
- package/skills/troubleshooting/SKILL.md +1 -0
- package/build/src/utils/string.js +0 -37
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { yargs, hideBin } from '../third_party/index.js';
|
|
7
|
-
export const
|
|
7
|
+
export const mcpOptions = {
|
|
8
8
|
autoConnect: {
|
|
9
9
|
type: 'boolean',
|
|
10
10
|
description: 'If specified, automatically connects to a browser (Chrome 144+) running locally from the user data directory identified by the channel param (default channel is stable). Requires the remote debugging server to be started in the Chrome instance via chrome://inspect/#remote-debugging.',
|
|
@@ -134,9 +134,10 @@ export const cliOptions = {
|
|
|
134
134
|
type: 'boolean',
|
|
135
135
|
description: `If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.`,
|
|
136
136
|
},
|
|
137
|
-
|
|
137
|
+
pageIdRouting: {
|
|
138
138
|
type: 'boolean',
|
|
139
|
-
describe: '
|
|
139
|
+
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.',
|
|
140
|
+
default: true,
|
|
140
141
|
},
|
|
141
142
|
experimentalDevtools: {
|
|
142
143
|
type: 'boolean',
|
|
@@ -148,11 +149,13 @@ export const cliOptions = {
|
|
|
148
149
|
},
|
|
149
150
|
memoryDebugging: {
|
|
150
151
|
type: 'boolean',
|
|
152
|
+
default: false,
|
|
151
153
|
describe: 'Whether to enable memory debugging tools.',
|
|
152
154
|
alias: 'experimentalMemory',
|
|
153
155
|
},
|
|
154
156
|
experimentalStructuredContent: {
|
|
155
157
|
type: 'boolean',
|
|
158
|
+
default: false,
|
|
156
159
|
describe: 'Whether to output structured formatted content.',
|
|
157
160
|
},
|
|
158
161
|
experimentalToonFormat: {
|
|
@@ -232,6 +235,12 @@ export const cliOptions = {
|
|
|
232
235
|
default: false,
|
|
233
236
|
describe: 'Set to true to enable third-party developer tools exposed by the inspected page itself',
|
|
234
237
|
},
|
|
238
|
+
categoryPwa: {
|
|
239
|
+
type: 'boolean',
|
|
240
|
+
hidden: false,
|
|
241
|
+
conflicts: ['autoConnect', 'browserUrl', 'wsEndpoint'],
|
|
242
|
+
describe: 'Set to true to include tools for automating Progressive Web Apps (install, launch, uninstall, and OS state). This feature is only supported with a pipe connection; autoConnect, browserUrl, and wsEndpoint are not supported.',
|
|
243
|
+
},
|
|
235
244
|
performanceCrux: {
|
|
236
245
|
type: 'boolean',
|
|
237
246
|
default: true,
|
|
@@ -324,10 +333,54 @@ export const cliOptions = {
|
|
|
324
333
|
'MCP roots and requires access to paths outside the temp directory.',
|
|
325
334
|
},
|
|
326
335
|
};
|
|
327
|
-
export function
|
|
336
|
+
export function getMcpOptionsForViaCli() {
|
|
337
|
+
if (!('default' in mcpOptions.headless)) {
|
|
338
|
+
throw new Error('headless cli option unexpectedly does not have a default');
|
|
339
|
+
}
|
|
340
|
+
if (!('default' in mcpOptions.experimentalStructuredContent)) {
|
|
341
|
+
throw new Error('experimentalStructuredContent cli option unexpectedly does not have a default');
|
|
342
|
+
}
|
|
343
|
+
if ('default' in mcpOptions.isolated) {
|
|
344
|
+
throw new Error('isolated cli option unexpectedly has a default');
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
...mcpOptions,
|
|
348
|
+
headless: {
|
|
349
|
+
...mcpOptions.headless,
|
|
350
|
+
default: true,
|
|
351
|
+
},
|
|
352
|
+
memoryDebugging: {
|
|
353
|
+
...mcpOptions.memoryDebugging,
|
|
354
|
+
default: true,
|
|
355
|
+
},
|
|
356
|
+
categoryExtensions: {
|
|
357
|
+
...mcpOptions.categoryExtensions,
|
|
358
|
+
default: true,
|
|
359
|
+
},
|
|
360
|
+
experimentalStructuredContent: {
|
|
361
|
+
...mcpOptions.experimentalStructuredContent,
|
|
362
|
+
default: true,
|
|
363
|
+
},
|
|
364
|
+
isolated: {
|
|
365
|
+
...mcpOptions.isolated,
|
|
366
|
+
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.',
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Exported only for testing to not trigger process exit.
|
|
372
|
+
*/
|
|
373
|
+
export function parser(version, argv = process.argv, env = process.env) {
|
|
374
|
+
const isViaCli = argv.includes('--viaCli') || argv.includes('--via-cli');
|
|
375
|
+
const options = isViaCli ? getMcpOptionsForViaCli() : mcpOptions;
|
|
328
376
|
const yargsInstance = yargs(hideBin(argv))
|
|
329
377
|
.scriptName('npx chrome-devtools-mcp@latest')
|
|
330
|
-
.
|
|
378
|
+
.parserConfiguration({
|
|
379
|
+
'strip-aliased': true,
|
|
380
|
+
'strip-dashed': true,
|
|
381
|
+
})
|
|
382
|
+
.options(options)
|
|
383
|
+
.showHelpOnFail(false, 'Specify --help for available options')
|
|
331
384
|
.middleware(args => {
|
|
332
385
|
// We can't set default in the options else
|
|
333
386
|
// Yargs will complain
|
|
@@ -341,6 +394,16 @@ export function parseArguments(version, argv = process.argv, env = process.env)
|
|
|
341
394
|
console.error("turning off usage statistics. process.env['CI'] || process.env['CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS'] is set.");
|
|
342
395
|
args.usageStatistics = false;
|
|
343
396
|
}
|
|
397
|
+
const cliOptionsAllowedArgs = [
|
|
398
|
+
...Object.keys(options),
|
|
399
|
+
// Yargs populated with positional args
|
|
400
|
+
'_',
|
|
401
|
+
'$0',
|
|
402
|
+
];
|
|
403
|
+
const unknownArgs = Object.keys(args).filter(arg => !cliOptionsAllowedArgs.includes(arg));
|
|
404
|
+
if (unknownArgs.length > 0) {
|
|
405
|
+
console.error(`Unknown arguments: ${unknownArgs.map(arg => `--${arg}`)}`);
|
|
406
|
+
}
|
|
344
407
|
})
|
|
345
408
|
.example([
|
|
346
409
|
[
|
|
@@ -407,7 +470,9 @@ export function parseArguments(version, argv = process.argv, env = process.env)
|
|
|
407
470
|
return yargsInstance
|
|
408
471
|
.wrap(Math.min(120, yargsInstance.terminalWidth()))
|
|
409
472
|
.help()
|
|
410
|
-
.version(version)
|
|
411
|
-
|
|
473
|
+
.version(version);
|
|
474
|
+
}
|
|
475
|
+
export function parseArguments(version, argv = process.argv, env = process.env) {
|
|
476
|
+
return parser(version, argv, env).parseSync();
|
|
412
477
|
}
|
|
413
|
-
//# sourceMappingURL=
|
|
478
|
+
//# sourceMappingURL=mcp-options.js.map
|
|
@@ -8,7 +8,7 @@ import fs from 'node:fs';
|
|
|
8
8
|
import net from 'node:net';
|
|
9
9
|
import { PipeTransport } from '../third_party/index.js';
|
|
10
10
|
import { getTempFilePath } from '../utils/files.js';
|
|
11
|
-
import { logger } from '../utils/logger.js';
|
|
11
|
+
import { logger, puppeteerLogger } from '../utils/logger.js';
|
|
12
12
|
import { DAEMON_SCRIPT_PATH, getSocketPath, getPidFilePath, isDaemonRunning, } from './utils.js';
|
|
13
13
|
const FILE_TIMEOUT = 10_000;
|
|
14
14
|
const READY_CHECK_INTERVAL = 100;
|
|
@@ -116,7 +116,7 @@ export async function sendCommand(command, sessionId, timeout = SEND_COMMAND_TIM
|
|
|
116
116
|
socket.destroy();
|
|
117
117
|
reject(new Error('Timeout waiting for daemon response'));
|
|
118
118
|
}, timeout);
|
|
119
|
-
const transport = new PipeTransport(socket, socket);
|
|
119
|
+
const transport = new PipeTransport(socket, socket, puppeteerLogger);
|
|
120
120
|
transport.onmessage = async (message) => {
|
|
121
121
|
clearTimeout(timer);
|
|
122
122
|
logger?.('onmessage', message);
|
|
@@ -165,6 +165,15 @@ export async function verifyDaemonVersion(sessionId, cliVersion) {
|
|
|
165
165
|
}
|
|
166
166
|
export async function handleResponse(response, format) {
|
|
167
167
|
if (response.isError) {
|
|
168
|
+
if (format === 'md') {
|
|
169
|
+
const chunks = [];
|
|
170
|
+
for (const content of response.content) {
|
|
171
|
+
if (content.type === 'text') {
|
|
172
|
+
chunks.push(content.text);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return chunks.join(' ');
|
|
176
|
+
}
|
|
168
177
|
return JSON.stringify(response.content);
|
|
169
178
|
}
|
|
170
179
|
const chunks = [];
|
|
@@ -10,7 +10,7 @@ import os from 'node:os';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import process from 'node:process';
|
|
12
12
|
import { Client, PipeTransport, StdioClientTransport, } from '../third_party/index.js';
|
|
13
|
-
import { logger } from '../utils/logger.js';
|
|
13
|
+
import { logger, puppeteerLogger } from '../utils/logger.js';
|
|
14
14
|
import { VERSION } from '../version.js';
|
|
15
15
|
import { DAEMON_CLIENT_NAME, getPidFilePath, getSocketPath, INDEX_SCRIPT_PATH, IS_WINDOWS, isDaemonRunning, assertValidSessionId, } from './utils.js';
|
|
16
16
|
const sessionId = process.env.CHROME_DEVTOOLS_MCP_SESSION_ID || '';
|
|
@@ -174,7 +174,7 @@ async function startSocketServer() {
|
|
|
174
174
|
}
|
|
175
175
|
return await new Promise((resolve, reject) => {
|
|
176
176
|
server = createServer(socket => {
|
|
177
|
-
const transport = new PipeTransport(socket, socket);
|
|
177
|
+
const transport = new PipeTransport(socket, socket, puppeteerLogger);
|
|
178
178
|
transport.onmessage = async (message) => {
|
|
179
179
|
logger?.('onmessage', message);
|
|
180
180
|
const response = await handleRequest(JSON.parse(message));
|
|
@@ -107,28 +107,16 @@ export async function createTargetUniverse(session) {
|
|
|
107
107
|
});
|
|
108
108
|
const setting = universe.settings.resolve(DevTools.SourceMapManager.lazyLoadingSettingDescriptor);
|
|
109
109
|
setting.set(true);
|
|
110
|
+
const skipAllPausesSetting = universe.settings.resolve(DevTools.skipAllPausesSettingDescriptor);
|
|
111
|
+
skipAllPausesSetting.set(true);
|
|
110
112
|
// @ts-expect-error devtools-frontend has diffrent types.
|
|
111
113
|
const connection = new DevTools.PuppeteerDevToolsConnection(session);
|
|
112
114
|
const targetManager = universe.context.get(DevTools.TargetManager);
|
|
113
|
-
targetManager.observeModels(DevTools.DebuggerModel, SKIP_ALL_PAUSES);
|
|
114
115
|
targetManager.observeModels(DevTools.NetworkManager.NetworkManager, DISABLE_NETWORK);
|
|
115
116
|
const target = targetManager.createTarget('main', '', 'frame', // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
116
117
|
/* parentTarget */ null, session.id(), undefined, connection);
|
|
117
118
|
return { target, universe, session };
|
|
118
119
|
}
|
|
119
|
-
// We don't want to pause any DevTools universe session ever on the MCP side.
|
|
120
|
-
//
|
|
121
|
-
// Note that calling `setSkipAllPauses` only affects the session on which it was
|
|
122
|
-
// sent. This means DevTools can still pause, step and do whatever. We just won't
|
|
123
|
-
// see the `Debugger.paused`/`Debugger.resumed` events on the MCP side.
|
|
124
|
-
const SKIP_ALL_PAUSES = {
|
|
125
|
-
modelAdded(model) {
|
|
126
|
-
void model.agent.invoke_setSkipAllPauses({ skip: true });
|
|
127
|
-
},
|
|
128
|
-
modelRemoved() {
|
|
129
|
-
// Do nothing.
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
120
|
// Not recording network requests in the DevTools universe.
|
|
133
121
|
//
|
|
134
122
|
// The network requests are collected through pptr and there isn't a use case for
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { createStackTraceForConsoleMessage, SymbolizedError, } from '../devtools/DevtoolsUtils.js';
|
|
7
|
-
import { UncaughtError } from '../PageCollector.js';
|
|
7
|
+
import { UncaughtError } from '../collectors/PageCollector.js';
|
|
8
8
|
import * as DevTools from '../third_party/index.js';
|
|
9
9
|
export class ConsoleFormatter {
|
|
10
10
|
#id;
|
|
@@ -14,6 +14,7 @@ export class ConsoleFormatter {
|
|
|
14
14
|
#resolvedArgs;
|
|
15
15
|
#stack;
|
|
16
16
|
#cause;
|
|
17
|
+
#includeStackInConcise;
|
|
17
18
|
isIgnored;
|
|
18
19
|
constructor(params) {
|
|
19
20
|
this.#id = params.id;
|
|
@@ -23,6 +24,7 @@ export class ConsoleFormatter {
|
|
|
23
24
|
this.#resolvedArgs = params.resolvedArgs ?? [];
|
|
24
25
|
this.#stack = params.stack;
|
|
25
26
|
this.#cause = params.cause;
|
|
27
|
+
this.#includeStackInConcise = params.includeStackInConcise ?? false;
|
|
26
28
|
this.isIgnored = params.isIgnored;
|
|
27
29
|
}
|
|
28
30
|
static async from(msg, options) {
|
|
@@ -45,7 +47,7 @@ export class ConsoleFormatter {
|
|
|
45
47
|
devTools: options?.devTools,
|
|
46
48
|
details: msg.details,
|
|
47
49
|
targetId: msg.targetId,
|
|
48
|
-
includeStackAndCause: options?.fetchDetailedData,
|
|
50
|
+
includeStackAndCause: options?.fetchDetailedData || options?.fetchStackTrace,
|
|
49
51
|
resolvedStackTraceForTesting: options?.resolvedStackTraceForTesting,
|
|
50
52
|
resolvedCauseForTesting: options?.resolvedCauseForTesting,
|
|
51
53
|
});
|
|
@@ -55,6 +57,7 @@ export class ConsoleFormatter {
|
|
|
55
57
|
text: error.message,
|
|
56
58
|
stack: error.stackTrace,
|
|
57
59
|
cause: error.cause,
|
|
60
|
+
includeStackInConcise: options.fetchStackTrace,
|
|
58
61
|
isIgnored,
|
|
59
62
|
});
|
|
60
63
|
}
|
|
@@ -86,7 +89,8 @@ export class ConsoleFormatter {
|
|
|
86
89
|
if (options.resolvedStackTraceForTesting) {
|
|
87
90
|
stack = options.resolvedStackTraceForTesting;
|
|
88
91
|
}
|
|
89
|
-
else if (options.fetchDetailedData
|
|
92
|
+
else if ((options.fetchDetailedData || options.fetchStackTrace) &&
|
|
93
|
+
options.devTools) {
|
|
90
94
|
try {
|
|
91
95
|
stack = await createStackTraceForConsoleMessage(options.devTools, msg);
|
|
92
96
|
}
|
|
@@ -101,6 +105,7 @@ export class ConsoleFormatter {
|
|
|
101
105
|
argCount: resolvedArgs.length || msg.args().length,
|
|
102
106
|
resolvedArgs,
|
|
103
107
|
stack,
|
|
108
|
+
includeStackInConcise: options.fetchStackTrace,
|
|
104
109
|
isIgnored,
|
|
105
110
|
});
|
|
106
111
|
}
|
|
@@ -112,6 +117,15 @@ export class ConsoleFormatter {
|
|
|
112
117
|
toStringDetailed() {
|
|
113
118
|
return convertConsoleMessageConciseDetailedToString(this.toJSONDetailed());
|
|
114
119
|
}
|
|
120
|
+
#getText() {
|
|
121
|
+
if (this.#text) {
|
|
122
|
+
return this.#text;
|
|
123
|
+
}
|
|
124
|
+
if (this.#resolvedArgs.length > 0) {
|
|
125
|
+
return formatArg(this.#resolvedArgs[0], this);
|
|
126
|
+
}
|
|
127
|
+
return '';
|
|
128
|
+
}
|
|
115
129
|
#getArgs() {
|
|
116
130
|
if (this.#resolvedArgs.length > 0) {
|
|
117
131
|
const args = [...this.#resolvedArgs];
|
|
@@ -124,12 +138,18 @@ export class ConsoleFormatter {
|
|
|
124
138
|
return [];
|
|
125
139
|
}
|
|
126
140
|
toJSON() {
|
|
127
|
-
|
|
141
|
+
const json = {
|
|
128
142
|
type: this.#type,
|
|
129
|
-
text: this.#
|
|
143
|
+
text: this.#getText(),
|
|
130
144
|
argsCount: this.#argCount,
|
|
131
145
|
id: this.#id,
|
|
132
146
|
};
|
|
147
|
+
if (this.#includeStackInConcise && this.#stack) {
|
|
148
|
+
json.stackTrace = formatStackTrace(this.#stack, this.#cause, this, {
|
|
149
|
+
includeNote: false,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return json;
|
|
133
153
|
}
|
|
134
154
|
/**
|
|
135
155
|
* Groups consecutive messages with the same type, text, and argument count.
|
|
@@ -143,7 +163,7 @@ export class ConsoleFormatter {
|
|
|
143
163
|
prev.message instanceof ConsoleFormatter &&
|
|
144
164
|
msg instanceof ConsoleFormatter &&
|
|
145
165
|
prev.message.#type === msg.#type &&
|
|
146
|
-
prev.message.#
|
|
166
|
+
prev.message.#getText() === msg.#getText() &&
|
|
147
167
|
prev.message.#argCount === msg.#argCount) {
|
|
148
168
|
prev.count++;
|
|
149
169
|
}
|
|
@@ -157,6 +177,9 @@ export class ConsoleFormatter {
|
|
|
157
177
|
type: message.#type,
|
|
158
178
|
text: message.#text,
|
|
159
179
|
argCount: message.#argCount,
|
|
180
|
+
stack: message.#stack,
|
|
181
|
+
cause: message.#cause,
|
|
182
|
+
includeStackInConcise: message.#includeStackInConcise,
|
|
160
183
|
isIgnored: message.isIgnored,
|
|
161
184
|
}, count)
|
|
162
185
|
: message);
|
|
@@ -165,7 +188,7 @@ export class ConsoleFormatter {
|
|
|
165
188
|
return {
|
|
166
189
|
id: this.#id,
|
|
167
190
|
type: this.#type,
|
|
168
|
-
text: this.#
|
|
191
|
+
text: this.#getText(),
|
|
169
192
|
argsCount: this.#argCount,
|
|
170
193
|
args: this.#getArgs().map(arg => formatArg(arg, this)),
|
|
171
194
|
stackTrace: this.#stack
|
|
@@ -191,7 +214,15 @@ export class GroupedConsoleFormatter extends ConsoleFormatter {
|
|
|
191
214
|
}
|
|
192
215
|
function convertConsoleMessageConciseToString(msg) {
|
|
193
216
|
const countSuffix = msg.count && msg.count > 1 ? ` [${msg.count} times]` : '';
|
|
194
|
-
|
|
217
|
+
const messageLine = `msgid=${msg.id} [${msg.type}] ${msg.text} (${msg.argsCount} args)${countSuffix}`;
|
|
218
|
+
if (!msg.stackTrace) {
|
|
219
|
+
return messageLine;
|
|
220
|
+
}
|
|
221
|
+
const indentedStackTrace = msg.stackTrace
|
|
222
|
+
.split('\n')
|
|
223
|
+
.map(line => ` ${line}`)
|
|
224
|
+
.join('\n');
|
|
225
|
+
return `${messageLine}\n${indentedStackTrace}`;
|
|
195
226
|
}
|
|
196
227
|
function convertConsoleMessageConciseDetailedToString(msg) {
|
|
197
228
|
const result = [
|
|
@@ -227,14 +258,16 @@ function formatArg(arg, formatter) {
|
|
|
227
258
|
return typeof arg === 'object' ? JSON.stringify(arg) : String(arg);
|
|
228
259
|
}
|
|
229
260
|
const STACK_TRACE_MAX_LINES = 50;
|
|
230
|
-
function formatStackTrace(stackTrace, cause, formatter) {
|
|
261
|
+
function formatStackTrace(stackTrace, cause, formatter, options) {
|
|
231
262
|
const lines = formatStackTraceInner(stackTrace, cause, formatter);
|
|
232
263
|
const includedLines = lines.slice(0, STACK_TRACE_MAX_LINES);
|
|
233
264
|
const reminderCount = lines.length - includedLines.length;
|
|
234
265
|
return [
|
|
235
266
|
...includedLines,
|
|
236
267
|
reminderCount > 0 ? `... and ${reminderCount} more frames` : '',
|
|
237
|
-
|
|
268
|
+
options?.includeNote === false
|
|
269
|
+
? ''
|
|
270
|
+
: 'Note: line and column numbers use 1-based indexing',
|
|
238
271
|
]
|
|
239
272
|
.filter(line => !!line)
|
|
240
273
|
.join('\n');
|
|
@@ -33,7 +33,7 @@ export class HeapSnapshotFormatter {
|
|
|
33
33
|
lines.push('nodeId,nodeName,type,distance,selfSize,retainedSize');
|
|
34
34
|
}
|
|
35
35
|
else if (isEdgeLike(firstItem)) {
|
|
36
|
-
lines.push('name,type,nodeId,nodeName');
|
|
36
|
+
lines.push('name,type,nodeId,nodeName,selfSize,retainedSize');
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
for (const item of items) {
|
|
@@ -41,7 +41,7 @@ export class HeapSnapshotFormatter {
|
|
|
41
41
|
lines.push(`${item.id},${item.name},${item.type},${item.distance},${formatBytesToKb(item.selfSize)},${formatBytesToKb(item.retainedSize)}`);
|
|
42
42
|
}
|
|
43
43
|
else if (isEdgeLike(item)) {
|
|
44
|
-
lines.push(`${item.name},${item.type},${item.node.id},${item.node.name}`);
|
|
44
|
+
lines.push(`${item.name},${item.type},${item.node.id},${item.node.name},${formatBytesToKb(item.node.selfSize)},${formatBytesToKb(item.node.retainedSize)}`);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
return lines.join('\n');
|
|
@@ -89,6 +89,14 @@ export class HeapSnapshotFormatter {
|
|
|
89
89
|
lines.push(`Unattributed Size: ${formatBytesToKb(sizes.noAttributionSize)}`);
|
|
90
90
|
return lines.join('\n');
|
|
91
91
|
}
|
|
92
|
+
static formatRetainedByContextSummary(summary) {
|
|
93
|
+
const lines = [];
|
|
94
|
+
lines.push(`Context count: ${summary.contextCount}`);
|
|
95
|
+
lines.push(`Retained by context size: ${formatBytesToKb(summary.retainedByContextSize)} (${summary.retainedByContextCount} objects)`);
|
|
96
|
+
lines.push(`Not retained by context size: ${formatBytesToKb(summary.notRetainedByContextSize)} (${summary.notRetainedByContextCount} objects)`);
|
|
97
|
+
lines.push(`Total size: ${formatBytesToKb(summary.totalSize)}`);
|
|
98
|
+
return lines.join('\n');
|
|
99
|
+
}
|
|
92
100
|
#getSortedAggregates() {
|
|
93
101
|
return Object.values(this.#aggregates).sort((a, b) => b.maxRet - a.maxRet);
|
|
94
102
|
}
|
|
@@ -144,7 +144,7 @@ export class IssueFormatter {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
function convertIssueConciseToString(issue) {
|
|
147
|
-
return `msgid=${issue.id} [issue] ${issue.title} (count: ${issue.count})`;
|
|
147
|
+
return `msgid=${issue.id} [issue] ${issue.title ?? 'Unknown Issue'} (count: ${issue.count})`;
|
|
148
148
|
}
|
|
149
149
|
function convertIssueDetailedToString(issue) {
|
|
150
150
|
const result = [];
|
|
@@ -38,7 +38,7 @@ export class NetworkFormatter {
|
|
|
38
38
|
const requestBodyNotAvailableMessage = '<Request body not available anymore>';
|
|
39
39
|
if (this.#options.requestFilePath) {
|
|
40
40
|
if (!this.#options.saveFile) {
|
|
41
|
-
throw new Error('saveFile
|
|
41
|
+
throw new Error('Unable to save the request body to a file: no saveFile callback was configured.');
|
|
42
42
|
}
|
|
43
43
|
if (data) {
|
|
44
44
|
const result = await this.#options.saveFile(Buffer.from(data), this.#options.requestFilePath, '.network-request');
|
|
@@ -65,7 +65,7 @@ export class NetworkFormatter {
|
|
|
65
65
|
try {
|
|
66
66
|
const buffer = await response.buffer();
|
|
67
67
|
if (!this.#options.saveFile) {
|
|
68
|
-
throw new Error('saveFile
|
|
68
|
+
throw new Error('Unable to save the response body to a file: no saveFile callback was configured.');
|
|
69
69
|
}
|
|
70
70
|
const result = await this.#options.saveFile(buffer, this.#options.responseFilePath, '.network-response');
|
|
71
71
|
this.#responseBodyFilePath = result.filename;
|
|
@@ -86,7 +86,7 @@ export class NetworkFormatter {
|
|
|
86
86
|
return convertNetworkRequestConciseToString(this.toJSON());
|
|
87
87
|
}
|
|
88
88
|
toStringDetailed() {
|
|
89
|
-
return
|
|
89
|
+
return convertNetworkRequestDetailedToStringDetailed(this.toJSONDetailed());
|
|
90
90
|
}
|
|
91
91
|
toJSON() {
|
|
92
92
|
return {
|
|
@@ -181,19 +181,19 @@ function convertNetworkRequestConciseToString(data) {
|
|
|
181
181
|
// TODO truncate the URL
|
|
182
182
|
return `reqid=${data.requestId} ${data.method} ${data.url} [${data.status}]${data.selectedInDevToolsUI ? ` [selected in the DevTools Network panel]` : ''}`;
|
|
183
183
|
}
|
|
184
|
-
function
|
|
184
|
+
function formatHeaders(headers) {
|
|
185
185
|
const response = [];
|
|
186
186
|
for (const [name, value] of Object.entries(headers)) {
|
|
187
187
|
response.push(`- ${name}:${value}`);
|
|
188
188
|
}
|
|
189
189
|
return response;
|
|
190
190
|
}
|
|
191
|
-
function
|
|
191
|
+
function convertNetworkRequestDetailedToStringDetailed(data) {
|
|
192
192
|
const response = [];
|
|
193
193
|
response.push(`## Request ${data.url}`);
|
|
194
194
|
response.push(`Status: ${data.status}`);
|
|
195
195
|
response.push(`### Request Headers`);
|
|
196
|
-
for (const line of
|
|
196
|
+
for (const line of formatHeaders(data.requestHeaders)) {
|
|
197
197
|
response.push(line);
|
|
198
198
|
}
|
|
199
199
|
if (data.requestBody) {
|
|
@@ -206,7 +206,7 @@ function converNetworkRequestDetailedToStringDetailed(data) {
|
|
|
206
206
|
}
|
|
207
207
|
if (data.responseHeaders) {
|
|
208
208
|
response.push(`### Response Headers`);
|
|
209
|
-
for (const line of
|
|
209
|
+
for (const line of formatHeaders(data.responseHeaders)) {
|
|
210
210
|
response.push(line);
|
|
211
211
|
}
|
|
212
212
|
}
|
package/build/src/index.js
CHANGED
|
@@ -12,9 +12,19 @@ import { McpServer, SetLevelRequestSchema, ListRootsResultSchema, RootsListChang
|
|
|
12
12
|
import { ToolHandler } from './ToolHandler.js';
|
|
13
13
|
import { createTools } from './tools/tools.js';
|
|
14
14
|
import { logger } from './utils/logger.js';
|
|
15
|
-
import { Mutex } from './third_party/index.js';
|
|
15
|
+
import { Mutex, puppeteer } from './third_party/index.js';
|
|
16
16
|
import { VERSION } from './version.js';
|
|
17
17
|
export { buildFlag } from './ToolHandler.js';
|
|
18
|
+
puppeteer.setFollowSymlinks(false);
|
|
19
|
+
/**
|
|
20
|
+
* Timeout for a `roots/list` that a tool call is waiting on, matching the 5s
|
|
21
|
+
* default used for page operations. `getContext()` awaits it while
|
|
22
|
+
* `ToolHandler` holds the tool mutex, so leaving it unbounded lets a client
|
|
23
|
+
* that negotiates `roots` but does not answer block every tool for the SDK's
|
|
24
|
+
* default of 60s. Background refreshes are not bounded by this, so roots a
|
|
25
|
+
* slow client sends late still land.
|
|
26
|
+
*/
|
|
27
|
+
const ROOTS_REQUEST_TIMEOUT = 5_000;
|
|
18
28
|
export async function createMcpServer(serverArgs, options) {
|
|
19
29
|
if (serverArgs.usageStatistics) {
|
|
20
30
|
ClearcutLogger.initialize({
|
|
@@ -34,13 +44,21 @@ export async function createMcpServer(serverArgs, options) {
|
|
|
34
44
|
server.server.setRequestHandler(SetLevelRequestSchema, () => {
|
|
35
45
|
return {};
|
|
36
46
|
});
|
|
37
|
-
|
|
47
|
+
// Roots are client state rather than browser state, so the last listing stays
|
|
48
|
+
// valid across browser reconnects and only the client can invalidate it, via
|
|
49
|
+
// the `roots/list_changed` notification handled below
|
|
50
|
+
let lastRoots;
|
|
51
|
+
// `timeout` is only passed where a tool call is waiting on the result – the
|
|
52
|
+
// background refreshes below block nobody, so bounding them would just discard
|
|
53
|
+
// roots a slow client was about to send
|
|
54
|
+
const updateRoots = async (timeout) => {
|
|
38
55
|
if (!server.server.getClientCapabilities()?.roots) {
|
|
39
56
|
return;
|
|
40
57
|
}
|
|
41
58
|
try {
|
|
42
|
-
const roots = await server.server.request({ method: 'roots/list' }, ListRootsResultSchema);
|
|
43
|
-
|
|
59
|
+
const roots = await server.server.request({ method: 'roots/list' }, ListRootsResultSchema, timeout === undefined ? undefined : { timeout });
|
|
60
|
+
lastRoots = roots.roots;
|
|
61
|
+
context?.setRoots(lastRoots);
|
|
44
62
|
}
|
|
45
63
|
catch (e) {
|
|
46
64
|
logger?.('Failed to list roots', e);
|
|
@@ -121,7 +139,17 @@ export async function createMcpServer(serverArgs, options) {
|
|
|
121
139
|
// Surfaces a one-time note in the next response after a reconnect.
|
|
122
140
|
reconnected: context !== undefined,
|
|
123
141
|
});
|
|
124
|
-
|
|
142
|
+
if (lastRoots === undefined) {
|
|
143
|
+
// Nothing listed yet, so this call has to wait – bounded, since it is
|
|
144
|
+
// holding the tool mutex, and a later background refresh still lands
|
|
145
|
+
await updateRoots(ROOTS_REQUEST_TIMEOUT);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// Carry the known roots over and refresh out of band, so a reconnect
|
|
149
|
+
// never pays for a client round-trip
|
|
150
|
+
context.setRoots(lastRoots);
|
|
151
|
+
void updateRoots();
|
|
152
|
+
}
|
|
125
153
|
}
|
|
126
154
|
return context;
|
|
127
155
|
}
|
|
@@ -5,12 +5,19 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import fsSync from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
|
-
import { DevTools } from '
|
|
9
|
-
import { createIdGenerator, stableIdSymbol, } from '
|
|
8
|
+
import { DevTools } from '../third_party/index.js';
|
|
9
|
+
import { createIdGenerator, stableIdSymbol, } from '../utils/id.js';
|
|
10
|
+
const VALID_EXTENSIONS = ['.heapsnapshot', '.heaptimeline'];
|
|
11
|
+
function hasValidHeapSnapshotExtension(filePath) {
|
|
12
|
+
return VALID_EXTENSIONS.some(ext => filePath.endsWith(ext));
|
|
13
|
+
}
|
|
10
14
|
export class HeapSnapshotManager {
|
|
11
15
|
#snapshotIdGenerator = createIdGenerator();
|
|
12
16
|
#snapshots = new Map();
|
|
13
17
|
async getSnapshot(filePath) {
|
|
18
|
+
if (!hasValidHeapSnapshotExtension(filePath)) {
|
|
19
|
+
throw new Error(`File ${filePath} must have a .heapsnapshot or .heaptimeline extension.`);
|
|
20
|
+
}
|
|
14
21
|
const absolutePath = path.resolve(filePath);
|
|
15
22
|
const cached = this.#snapshots.get(absolutePath);
|
|
16
23
|
if (cached) {
|
|
@@ -72,6 +79,10 @@ export class HeapSnapshotManager {
|
|
|
72
79
|
const snapshot = await this.getSnapshot(filePath);
|
|
73
80
|
return await snapshot.getNativeContextSizes();
|
|
74
81
|
}
|
|
82
|
+
async getRetainedByContextSummary(filePath) {
|
|
83
|
+
const snapshot = await this.getSnapshot(filePath);
|
|
84
|
+
return await snapshot.getRetainedByContextSummary();
|
|
85
|
+
}
|
|
75
86
|
async getOrCreateIdForClassKey(filePath, classKey) {
|
|
76
87
|
const cached = this.#getCachedSnapshot(filePath);
|
|
77
88
|
let id = cached.classKeyToId.get(classKey);
|
|
@@ -126,13 +137,13 @@ export class HeapSnapshotManager {
|
|
|
126
137
|
}
|
|
127
138
|
return await snapshot.getDominatorsOf(nodeIndex);
|
|
128
139
|
}
|
|
129
|
-
async getEdges(filePath, nodeId) {
|
|
140
|
+
async getEdges(filePath, nodeId, options) {
|
|
130
141
|
const snapshot = await this.getSnapshot(filePath);
|
|
131
142
|
const nodeIndex = await snapshot.nodeIndexForId(nodeId);
|
|
132
143
|
if (nodeIndex === undefined) {
|
|
133
144
|
throw new Error(`Node with ID ${nodeId} not found`);
|
|
134
145
|
}
|
|
135
|
-
const provider = snapshot.createEdgesProvider(nodeIndex);
|
|
146
|
+
const provider = snapshot.createEdgesProvider(nodeIndex, options);
|
|
136
147
|
return await provider.serializeItemsRange(0, Infinity);
|
|
137
148
|
}
|
|
138
149
|
async getClassDiffs(baseFilePath, currentFilePath) {
|
|
@@ -201,7 +212,7 @@ export class HeapSnapshotManager {
|
|
|
201
212
|
async #loadSnapshot(absolutePath, uid) {
|
|
202
213
|
const workerProxy = new DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotWorkerProxy(() => {
|
|
203
214
|
/* noop */
|
|
204
|
-
}, DevTools.Common.Console.Console.instance(), import.meta.resolve('
|
|
215
|
+
}, DevTools.Common.Console.Console.instance(), import.meta.resolve('../third_party/devtools-heap-snapshot-worker.js'));
|
|
205
216
|
try {
|
|
206
217
|
const { promise: snapshotPromise, resolve: resolveSnapshot } = Promise.withResolvers();
|
|
207
218
|
const loaderProxy = workerProxy.createLoader(uid, snapshotProxy => {
|
|
@@ -231,6 +242,11 @@ export class HeapSnapshotManager {
|
|
|
231
242
|
const snapshot = await this.getSnapshot(filePath);
|
|
232
243
|
return await snapshot.getDuplicateStrings();
|
|
233
244
|
}
|
|
245
|
+
async queryObjects(filePath, options) {
|
|
246
|
+
const snapshot = await this.getSnapshot(filePath);
|
|
247
|
+
const provider = snapshot.queryObjects(options);
|
|
248
|
+
return await provider.serializeItemsRange(0, Infinity);
|
|
249
|
+
}
|
|
234
250
|
hasSnapshots() {
|
|
235
251
|
return this.#snapshots.size > 0;
|
|
236
252
|
}
|
|
@@ -82,4 +82,4 @@ export function getInsightOutput(result, insightSetId, insightName, deviceScope)
|
|
|
82
82
|
const formatter = new DevTools.PerformanceInsightFormatter(DevTools.AgentFocus.fromParsedTrace(result.parsedTrace), matchingInsight, deviceScope);
|
|
83
83
|
return { output: formatter.formatInsight() };
|
|
84
84
|
}
|
|
85
|
-
//# sourceMappingURL=
|
|
85
|
+
//# sourceMappingURL=PerformanceTrace.js.map
|
|
@@ -58,7 +58,10 @@ export class ClearcutLogger {
|
|
|
58
58
|
}
|
|
59
59
|
setClientName(clientName) {
|
|
60
60
|
const lowerName = clientName.toLowerCase();
|
|
61
|
-
if (lowerName.includes('claude')) {
|
|
61
|
+
if (lowerName.includes('claude-desktop')) {
|
|
62
|
+
this.#mcpClient = McpClient.MCP_CLIENT_CLAUDE_DESKTOP;
|
|
63
|
+
}
|
|
64
|
+
else if (lowerName.includes('claude')) {
|
|
62
65
|
this.#mcpClient = McpClient.MCP_CLIENT_CLAUDE_CODE;
|
|
63
66
|
}
|
|
64
67
|
else if (lowerName.includes('gemini')) {
|
|
@@ -70,12 +73,21 @@ export class ClearcutLogger {
|
|
|
70
73
|
else if (lowerName.includes('openclaw')) {
|
|
71
74
|
this.#mcpClient = McpClient.MCP_CLIENT_OPENCLAW;
|
|
72
75
|
}
|
|
76
|
+
else if (lowerName.includes('opencode')) {
|
|
77
|
+
this.#mcpClient = McpClient.MCP_CLIENT_OPENCODE;
|
|
78
|
+
}
|
|
73
79
|
else if (lowerName.includes('codex')) {
|
|
74
80
|
this.#mcpClient = McpClient.MCP_CLIENT_CODEX;
|
|
75
81
|
}
|
|
76
82
|
else if (lowerName.includes('antigravity')) {
|
|
77
83
|
this.#mcpClient = McpClient.MCP_CLIENT_ANTIGRAVITY;
|
|
78
84
|
}
|
|
85
|
+
else if (lowerName.includes('grok') || lowerName.includes('xai')) {
|
|
86
|
+
this.#mcpClient = McpClient.MCP_CLIENT_GROK;
|
|
87
|
+
}
|
|
88
|
+
else if (lowerName.includes('copilot')) {
|
|
89
|
+
this.#mcpClient = McpClient.MCP_CLIENT_GITHUB_COPILOT;
|
|
90
|
+
}
|
|
79
91
|
else {
|
|
80
92
|
this.#mcpClient = McpClient.MCP_CLIENT_OTHER;
|
|
81
93
|
}
|