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
|
@@ -63,6 +63,13 @@ import path from 'node:path';
|
|
|
63
63
|
import { Mutex, puppeteer } from './third_party/index.js';
|
|
64
64
|
import { logger, puppeteerLogger } from './utils/logger.js';
|
|
65
65
|
import { isAllowedUrl } from './utils/url.js';
|
|
66
|
+
/**
|
|
67
|
+
* Identity token for an in-flight connect/launch attempt. Instances carry no
|
|
68
|
+
* data and are never inspected structurally — only ever compared by
|
|
69
|
+
* reference (`!==`) — see BrowserManager#abandonPendingAttempt().
|
|
70
|
+
*/
|
|
71
|
+
class BrowserAttempt {
|
|
72
|
+
}
|
|
66
73
|
export class BrowserManager {
|
|
67
74
|
#browser;
|
|
68
75
|
#browserMode;
|
|
@@ -71,6 +78,7 @@ export class BrowserManager {
|
|
|
71
78
|
#closingCount = 0;
|
|
72
79
|
#serverArgs;
|
|
73
80
|
#options;
|
|
81
|
+
#browserAttempt = new BrowserAttempt();
|
|
74
82
|
constructor(serverArgs, options = {}) {
|
|
75
83
|
this.#serverArgs = serverArgs;
|
|
76
84
|
this.#options = options;
|
|
@@ -148,16 +156,33 @@ export class BrowserManager {
|
|
|
148
156
|
if (this.#closingCount > 0) {
|
|
149
157
|
throw new Error('Browser was closed while initializing.');
|
|
150
158
|
}
|
|
151
|
-
|
|
159
|
+
// Captured before acquiring #mutex, not after: a caller queued here can
|
|
160
|
+
// have its own timeout fire (abandonPendingAttempt()) while it's still
|
|
161
|
+
// waiting for the lock. Capturing only after acquiring it would let such
|
|
162
|
+
// a call silently adopt the freshly-rotated token as its own baseline
|
|
163
|
+
// once the lock frees up, defeating the abandonment check entirely.
|
|
164
|
+
const attempt = this.#browserAttempt;
|
|
165
|
+
const guard = __addDisposableResource(env_1, await this.#mutex.acquire(), false);
|
|
152
166
|
if (this.#closingCount > 0) {
|
|
153
167
|
throw new Error('Browser was closed while initializing.');
|
|
154
168
|
}
|
|
169
|
+
if (this.#browserAttempt !== attempt) {
|
|
170
|
+
// Abandoned while queued for the lock — #browser was never touched by
|
|
171
|
+
// this call, so bail immediately without #closeBrowser(), which could
|
|
172
|
+
// otherwise tear down a different, still-current attempt's browser.
|
|
173
|
+
throw new Error('Connection attempt was abandoned before it completed.');
|
|
174
|
+
}
|
|
155
175
|
if (!this.#browser?.connected) {
|
|
156
176
|
await this.#initBrowser();
|
|
157
177
|
}
|
|
158
|
-
if (this.#closingCount > 0 ||
|
|
178
|
+
if (this.#closingCount > 0 ||
|
|
179
|
+
this.#browserAttempt !== attempt ||
|
|
180
|
+
!this.#browser) {
|
|
181
|
+
const reason = this.#closingCount > 0
|
|
182
|
+
? 'Browser was closed while initializing.'
|
|
183
|
+
: 'Connection attempt was abandoned before it completed.';
|
|
159
184
|
await this.#closeBrowser();
|
|
160
|
-
throw new Error(
|
|
185
|
+
throw new Error(reason);
|
|
161
186
|
}
|
|
162
187
|
return this.#browser;
|
|
163
188
|
}
|
|
@@ -169,6 +194,27 @@ export class BrowserManager {
|
|
|
169
194
|
__disposeResources(env_1);
|
|
170
195
|
}
|
|
171
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Signals that whoever was waiting on the in-flight ensureBrowser() call
|
|
199
|
+
* has given up (e.g. a tool-call timeout). There's no way to cancel a
|
|
200
|
+
* pending connect()/launch(), so this doesn't stop it — it rotates the
|
|
201
|
+
* token to a fresh value and clears #initPromise, so a late-resolving
|
|
202
|
+
* attempt gets discarded by #ensureBrowserLocked() instead of silently
|
|
203
|
+
* installed for a caller who already walked away.
|
|
204
|
+
*
|
|
205
|
+
* Also forgets the cached #browser, if any. This only ever fires from a
|
|
206
|
+
* getContext()-level timeout, which covers both ensureBrowser() and the
|
|
207
|
+
* McpContext initialization built on it — if ensureBrowser() already
|
|
208
|
+
* resolved and it's that later step hanging (e.g. a dead CDP transport),
|
|
209
|
+
* the token rotation alone does nothing, since #browser is already
|
|
210
|
+
* cached. Safe to forget unconditionally here: the tool mutex serializes
|
|
211
|
+
* every call, so there's no concurrent caller to disrupt.
|
|
212
|
+
*/
|
|
213
|
+
abandonPendingAttempt() {
|
|
214
|
+
this.#browserAttempt = new BrowserAttempt();
|
|
215
|
+
this.#initPromise = undefined;
|
|
216
|
+
this.#forgetCurrentBrowser();
|
|
217
|
+
}
|
|
172
218
|
async #initBrowser() {
|
|
173
219
|
if (this.#serverArgs.browserUrl ||
|
|
174
220
|
this.#serverArgs.wsEndpoint ||
|
|
@@ -243,7 +289,9 @@ export class BrowserManager {
|
|
|
243
289
|
}
|
|
244
290
|
this.#browserMode = 'launched';
|
|
245
291
|
this.#browser = browser;
|
|
246
|
-
|
|
292
|
+
const launched = browser;
|
|
293
|
+
launched.once('disconnected', () => this.#evictIfCurrent(launched));
|
|
294
|
+
return launched;
|
|
247
295
|
}
|
|
248
296
|
catch (error) {
|
|
249
297
|
await browser?.close().catch(() => {
|
|
@@ -266,23 +314,30 @@ export class BrowserManager {
|
|
|
266
314
|
}
|
|
267
315
|
}
|
|
268
316
|
async #connect() {
|
|
269
|
-
const { browserUrl: browserURL, wsEndpoint, wsHeaders, autoConnect: isAutoConnect, userDataDir, blockedUrlPattern: blocklist, allowedUrlPattern: allowlist, } = this.#serverArgs;
|
|
317
|
+
const { browserUrl: browserURL, wsEndpoint, wsHeaders, autoConnect: isAutoConnect, userDataDir, blockedUrlPattern: blocklist, allowedUrlPattern: allowlist, categoryExtensions: enableExtensions, } = this.#serverArgs;
|
|
270
318
|
// Important: only pass channel, if autoConnect is true.
|
|
271
319
|
const channel = isAutoConnect ? this.#serverArgs.channel : undefined;
|
|
272
320
|
const connectOptions = {
|
|
273
|
-
targetFilter: _a.makeTargetFilter(),
|
|
321
|
+
targetFilter: _a.makeTargetFilter(enableExtensions),
|
|
274
322
|
defaultViewport: null,
|
|
275
323
|
handleDevToolsAsPage: true,
|
|
276
324
|
blocklist,
|
|
277
325
|
allowlist,
|
|
278
326
|
logger: puppeteerLogger,
|
|
327
|
+
// Detects a transport that died without a close frame (e.g. an adb
|
|
328
|
+
// port-forward torn down mid-call). Puppeteer pings the socket
|
|
329
|
+
// periodically and terminates it on a missed pong, which rejects the
|
|
330
|
+
// in-flight CDP calls and fires `disconnected` so #evictIfCurrent()
|
|
331
|
+
// drops the stale handle. Without this, such a call would hang until
|
|
332
|
+
// protocolTimeout while holding the tool mutex.
|
|
333
|
+
wsOptions: {
|
|
334
|
+
keepAlive: true,
|
|
335
|
+
headers: wsHeaders,
|
|
336
|
+
},
|
|
279
337
|
};
|
|
280
338
|
let autoConnect = false;
|
|
281
339
|
if (wsEndpoint) {
|
|
282
340
|
connectOptions.browserWSEndpoint = wsEndpoint;
|
|
283
|
-
if (wsHeaders) {
|
|
284
|
-
connectOptions.headers = wsHeaders;
|
|
285
|
-
}
|
|
286
341
|
}
|
|
287
342
|
else if (browserURL) {
|
|
288
343
|
connectOptions.browserURL = browserURL;
|
|
@@ -335,6 +390,7 @@ export class BrowserManager {
|
|
|
335
390
|
logger?.('Connected Puppeteer');
|
|
336
391
|
this.#browserMode = 'connected';
|
|
337
392
|
this.#browser = connected;
|
|
393
|
+
connected.once('disconnected', () => this.#evictIfCurrent(connected));
|
|
338
394
|
return connected;
|
|
339
395
|
}
|
|
340
396
|
catch (err) {
|
|
@@ -343,6 +399,71 @@ export class BrowserManager {
|
|
|
343
399
|
});
|
|
344
400
|
}
|
|
345
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* Drops the cached browser handle so the next ensureBrowser() call
|
|
404
|
+
* establishes a fresh connection. Only called from abandonPendingAttempt()
|
|
405
|
+
* when a getContext()-level timeout fires after ensureBrowser() already
|
|
406
|
+
* resolved, which means the handle looks connected but its CDP
|
|
407
|
+
* initialization is hanging.
|
|
408
|
+
*
|
|
409
|
+
* Also tears the browser down in the background: closes it if it was
|
|
410
|
+
* launched (so the Chrome subprocess doesn't leak), or disconnects if it
|
|
411
|
+
* was only connected to (so the transport and its listeners don't leak).
|
|
412
|
+
* Puppeteer's connection disposal rejects any in-flight CDP call, so a hung
|
|
413
|
+
* call settles instead of leaking forever.
|
|
414
|
+
*/
|
|
415
|
+
#forgetCurrentBrowser() {
|
|
416
|
+
const browser = this.#browser;
|
|
417
|
+
if (!browser) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const mode = this.#browserMode;
|
|
421
|
+
this.#browser = undefined;
|
|
422
|
+
this.#browserMode = undefined;
|
|
423
|
+
if (mode === 'launched') {
|
|
424
|
+
void this.#closeLaunchedBrowser(browser);
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
void browser.disconnect().catch(err => {
|
|
428
|
+
logger?.('Failed to disconnect forgotten browser', err);
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Handles a `disconnected` event fired by a browser we hold: clears the
|
|
434
|
+
* cached handle if it's still the current one, so the next ensureBrowser()
|
|
435
|
+
* call reconnects proactively rather than only discovering the staleness
|
|
436
|
+
* lazily on the next call's `!this.#browser?.connected` check. No teardown
|
|
437
|
+
* here — the browser is already disconnected/closed, that's why this
|
|
438
|
+
* fired. The identity guard makes a `disconnected` that fires late on an
|
|
439
|
+
* already-superseded browser a safe no-op.
|
|
440
|
+
*/
|
|
441
|
+
#evictIfCurrent(candidate) {
|
|
442
|
+
if (this.#browser !== candidate) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
this.#browser = undefined;
|
|
446
|
+
this.#browserMode = undefined;
|
|
447
|
+
}
|
|
448
|
+
async #closeLaunchedBrowser(browser) {
|
|
449
|
+
let timer;
|
|
450
|
+
try {
|
|
451
|
+
await Promise.race([
|
|
452
|
+
browser.close(),
|
|
453
|
+
new Promise((_, reject) => {
|
|
454
|
+
timer = setTimeout(() => reject(new Error('Timed out closing browser')), 5_000);
|
|
455
|
+
timer.unref?.();
|
|
456
|
+
}),
|
|
457
|
+
]);
|
|
458
|
+
}
|
|
459
|
+
catch (err) {
|
|
460
|
+
logger?.('Failed to close browser', err);
|
|
461
|
+
browser.process()?.kill('SIGKILL');
|
|
462
|
+
}
|
|
463
|
+
finally {
|
|
464
|
+
clearTimeout(timer);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
346
467
|
async #closeBrowser() {
|
|
347
468
|
const browser = this.#browser;
|
|
348
469
|
const mode = this.#browserMode;
|
|
@@ -352,9 +473,7 @@ export class BrowserManager {
|
|
|
352
473
|
return;
|
|
353
474
|
}
|
|
354
475
|
if (mode === 'launched') {
|
|
355
|
-
await browser
|
|
356
|
-
logger?.('Failed to close browser', err);
|
|
357
|
-
});
|
|
476
|
+
await this.#closeLaunchedBrowser(browser);
|
|
358
477
|
return;
|
|
359
478
|
}
|
|
360
479
|
await browser.disconnect().catch(err => {
|
|
@@ -372,7 +491,7 @@ export class BrowserManager {
|
|
|
372
491
|
try {
|
|
373
492
|
this.#initPromise = undefined;
|
|
374
493
|
this.#closingCount++;
|
|
375
|
-
const
|
|
494
|
+
const guard = __addDisposableResource(env_2, await this.#mutex.acquire(), false);
|
|
376
495
|
try {
|
|
377
496
|
await this.#closeBrowser();
|
|
378
497
|
}
|