Skip to content

Chrome DevTools for coding agents

chore: remove MCP logging notifications for DevTools comments (#3162)

Alex Rudenkob8b1f13f1587
diff --git a/src/McpContext.ts b/src/McpContext.ts
index 3c2727f3..a28565a2 100644
--- a/src/McpContext.ts
+++ b/src/McpContext.ts
@@ -75,8 +75,6 @@ export interface McpContextOptions {
navigationTimeout?: number;
// Whether extension tools and targets are enabled.
categoryExtensions?: boolean;
- // Callback when a notification should be emitted to MCP client.
- onNotification?: (message: string) => void;
// Shared heap snapshot manager to preserve loaded snapshots across browser reconnects.
heapSnapshotManager: HeapSnapshotManager;
// Returns the browser to use. Called by ensureBrowser(), so the browser
@@ -681,7 +679,6 @@ export class McpContext implements Context, BrowserlessContext {
),
navigationTimeout: this.#options.navigationTimeout,
sourceMaps: this.#options.sourceMaps,
- onNotification: this.#options.onNotification,
});
}
this.#mcpPages.set(target, mcpPage);
diff --git a/src/McpPage.ts b/src/McpPage.ts
index 554e68fb..47fe9f4e 100644
--- a/src/McpPage.ts
+++ b/src/McpPage.ts
@@ -182,7 +182,6 @@ export class McpPage implements ContextPage {
#navigationTimeout: number;
#sourceMaps: boolean;
#commentBridge?: DevToolsCommentBridge;
- #onNotification?: (message: string) => void;
constructor(
target: Target,
@@ -193,14 +192,12 @@ export class McpPage implements ContextPage {
isolatedContextName?: string;
navigationTimeout?: number;
sourceMaps?: boolean;
- onNotification?: (message: string) => void;
},
) {
this.#hasNetworkBlockOrAllowlist = options.hasNetworkBlockOrAllowlist;
this.#locatorClass = options.locatorClass;
this.#navigationTimeout = options.navigationTimeout ?? NAVIGATION_TIMEOUT;
this.#sourceMaps = options.sourceMaps ?? true;
- this.#onNotification = options.onNotification;
this.target = target;
this.id = id;
this.isolatedContextName = options.isolatedContextName;
@@ -555,9 +552,7 @@ export class McpPage implements ContextPage {
devtoolsPage: Page,
): Promise<DevToolsCommentBridge | undefined> {
if (!this.#commentBridge) {
- this.#commentBridge = new DevToolsCommentBridge({
- onNotification: this.#onNotification,
- });
+ this.#commentBridge = new DevToolsCommentBridge();
}
const attached = await this.#commentBridge.attach(devtoolsPage);
return attached ? this.#commentBridge : undefined;
diff --git a/src/devtools/DevToolsCommentBridge.ts b/src/devtools/DevToolsCommentBridge.ts
index 4c58a9d7..7fe30366 100644
--- a/src/devtools/DevToolsCommentBridge.ts
+++ b/src/devtools/DevToolsCommentBridge.ts
@@ -9,25 +9,23 @@ import type {CD4ACommentThread} from '../types.js';
import {logger} from '../utils/logger.js';
export interface DevToolsCommentBridgeOptions {
- onNotification?: (message: string) => void;
debounceMs?: number;
}
const DEFAULT_DEBOUNCE_MS = 200;
/**
- * Manages the bidirectional bridge between DevTools frontend comments
- * and the MCP server notification system.
+ * Manages the bridge between DevTools frontend comments and the MCP server.
+ * Comment events are debounced and delivered to callers that wait for them
+ * through `waitForCommentEvent`.
*/
export class DevToolsCommentBridge {
- readonly #onNotification?: (message: string) => void;
readonly #debounceMs: number;
#commentDebounceTimer?: NodeJS.Timeout;
readonly #attachedPages = new Set<Page>();
readonly #commentWaiters = new Set<(changed: boolean) => void>();
constructor(options?: DevToolsCommentBridgeOptions) {
- this.#onNotification = options?.onNotification;
this.#debounceMs = options?.debounceMs ?? DEFAULT_DEBOUNCE_MS;
}
@@ -140,7 +138,6 @@ export class DevToolsCommentBridge {
clearTimeout(this.#commentDebounceTimer);
}
this.#commentDebounceTimer = setTimeout(() => {
- this.#onNotification?.('DevTools comment threads updated');
this.#notifyCommentWaiters(true);
}, this.#debounceMs);
}
diff --git a/src/index.ts b/src/index.ts
index 96d00f4c..6a3549b7 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -114,16 +114,6 @@ export class McpServer {
categoryExtensions: this.#serverArgs.categoryExtensions,
heapSnapshotManager: this.#heapSnapshotManager,
getBrowser: () => this.#browserManager.ensureBrowser(),
- onNotification: (message: string) => {
- void this.server
- .sendLoggingMessage({
- level: 'info',
- data: message,
- })
- .catch(e => {
- logger?.('Failed to send MCP notification', e);
- });
- },
});
this.#context.setRoots(this.#combinedRoots());
diff --git a/tests/devtools/DevToolsCommentBridge.test.ts b/tests/devtools/DevToolsCommentBridge.test.ts
index c086cac8..fbe26c85 100644
--- a/tests/devtools/DevToolsCommentBridge.test.ts
+++ b/tests/devtools/DevToolsCommentBridge.test.ts
@@ -118,10 +118,9 @@ describe('DevToolsCommentBridge', () => {
sinon.assert.calledTwice(devtoolsPage.evaluate);
});
- it('debounces comment notifications', async () => {
+ it('debounces comment events', async () => {
const devtoolsPage = createMockPuppeteerPage();
devtoolsPage.evaluate.resolves(true);
- const onNotification = sinon.stub();
let exposedCallback: (() => void) | undefined;
devtoolsPage.exposeFunction.callsFake((name: string, fn: unknown) => {
@@ -133,13 +132,16 @@ describe('DevToolsCommentBridge', () => {
return Promise.resolve();
});
- const bridge = new DevToolsCommentBridge({
- onNotification,
- debounceMs: 150,
- });
+ const bridge = new DevToolsCommentBridge({debounceMs: 150});
await bridge.attach(devtoolsPage);
+ const waiting = bridge.waitForCommentEvent(10_000);
+ let settled = false;
+ void waiting.then(() => {
+ settled = true;
+ });
+
assert.strictEqual(typeof exposedCallback, 'function');
if (exposedCallback) {
// Trigger multiple times rapidly
@@ -148,20 +150,16 @@ describe('DevToolsCommentBridge', () => {
exposedCallback();
}
- clock.tick(100);
- sinon.assert.notCalled(onNotification);
+ await clock.tickAsync(100);
+ assert.strictEqual(settled, false);
- clock.tick(60);
- sinon.assert.calledOnceWithExactly(
- onNotification,
- 'DevTools comment threads updated',
- );
+ await clock.tickAsync(60);
+ assert.strictEqual(await waiting, true);
});
it('clears debounce timer on dispose', async () => {
const devtoolsPage = createMockPuppeteerPage();
devtoolsPage.evaluate.resolves(true);
- const onNotification = sinon.stub();
let exposedCallback: (() => void) | undefined;
devtoolsPage.exposeFunction.callsFake((name: string, fn: unknown) => {
@@ -173,13 +171,11 @@ describe('DevToolsCommentBridge', () => {
return Promise.resolve();
});
- const bridge = new DevToolsCommentBridge({
- onNotification,
- debounceMs: 150,
- });
+ const bridge = new DevToolsCommentBridge({debounceMs: 150});
await bridge.attach(devtoolsPage);
+ const waiting = bridge.waitForCommentEvent(10_000);
assert.strictEqual(typeof exposedCallback, 'function');
if (exposedCallback) {
exposedCallback();
@@ -187,8 +183,8 @@ describe('DevToolsCommentBridge', () => {
bridge.dispose();
- clock.tick(200);
- sinon.assert.notCalled(onNotification);
+ await clock.tickAsync(200);
+ assert.strictEqual(await waiting, false);
sinon.assert.calledThrice(devtoolsPage.evaluate);
});