Skip to content

Commit 08e9a9f

Browse files
authored
refactor: disable issues in list_console_messages for now (#575)
Disabled the feature until the detail tool is ready.
1 parent 305d7d7 commit 08e9a9f

File tree

6 files changed

+99
-56
lines changed

6 files changed

+99
-56
lines changed

src/PageCollector.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
1717

1818
import {FakeIssuesManager} from './DevtoolsUtils.js';
19+
import {features} from './features.js';
1920
import {logger} from './logger.js';
2021
import type {
2122
CDPSession,
@@ -231,6 +232,9 @@ export class ConsoleCollector extends PageCollector<
231232

232233
override addPage(page: Page): void {
233234
super.addPage(page);
235+
if (!features.issues) {
236+
return;
237+
}
234238
if (!this.#subscribedPages.has(page)) {
235239
const subscriber = new PageIssueSubscriber(page);
236240
this.#subscribedPages.set(page, subscriber);

src/features.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
let issuesEnabled = false;
7+
8+
export const features = {
9+
get issues() {
10+
return issuesEnabled;
11+
},
12+
};
13+
14+
export function setIssuesEnabled(value: boolean) {
15+
issuesEnabled = value;
16+
}

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import './polyfill.js';
99
import type {Channel} from './browser.js';
1010
import {ensureBrowserConnected, ensureBrowserLaunched} from './browser.js';
1111
import {parseArguments} from './cli.js';
12+
import {features} from './features.js';
1213
import {loadIssueDescriptions} from './issue-descriptions.js';
1314
import {logger, saveLogsToFile} from './logger.js';
1415
import {McpContext} from './McpContext.js';
@@ -190,7 +191,9 @@ for (const tool of tools) {
190191
registerTool(tool);
191192
}
192193

193-
await loadIssueDescriptions();
194+
if (features.issues) {
195+
await loadIssueDescriptions();
196+
}
194197
const transport = new StdioServerTransport();
195198
await server.connect(transport);
196199
logger('Chrome DevTools MCP Server connected');

src/tools/console.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
import {features} from '../features.js';
78
import {zod} from '../third_party/index.js';
89
import type {ConsoleMessageType} from '../third_party/index.js';
910

1011
import {ToolCategory} from './categories.js';
1112
import {defineTool} from './ToolDefinition.js';
1213
type ConsoleResponseType = ConsoleMessageType | 'issue';
1314

14-
const FILTERABLE_MESSAGE_TYPES: readonly [
15+
const FILTERABLE_MESSAGE_TYPES: [
1516
ConsoleResponseType,
1617
...ConsoleResponseType[],
1718
] = [
@@ -37,6 +38,10 @@ const FILTERABLE_MESSAGE_TYPES: readonly [
3738
'issue',
3839
];
3940

41+
if (features.issues) {
42+
FILTERABLE_MESSAGE_TYPES.push('issue');
43+
}
44+
4045
export const listConsoleMessages = defineTool({
4146
name: 'list_console_messages',
4247
description:

tests/PageCollector.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
import assert from 'node:assert';
7-
import {beforeEach, describe, it} from 'node:test';
7+
import {afterEach, beforeEach, describe, it} from 'node:test';
88

99
import type {
1010
Browser,
@@ -17,6 +17,7 @@ import type {
1717
import sinon from 'sinon';
1818

1919
import {AggregatedIssue} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
20+
import {setIssuesEnabled} from '../src/features.js';
2021
import type {ListenerMap} from '../src/PageCollector.js';
2122
import {
2223
ConsoleCollector,
@@ -357,6 +358,11 @@ describe('ConsoleCollector', () => {
357358
},
358359
},
359360
};
361+
setIssuesEnabled(true);
362+
});
363+
364+
afterEach(() => {
365+
setIssuesEnabled(false);
360366
});
361367

362368
it('emits issues on page', async () => {

tests/tools/console.test.ts

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
import assert from 'node:assert';
7-
import {before, describe, it} from 'node:test';
7+
import {afterEach, before, beforeEach, describe, it} from 'node:test';
88

9+
import {setIssuesEnabled} from '../../src/features.js';
910
import {loadIssueDescriptions} from '../../src/issue-descriptions.js';
1011
import {
1112
getConsoleMessage,
@@ -41,79 +42,87 @@ describe('console', () => {
4142
});
4243
});
4344

44-
it('lists issues', async () => {
45+
it('work with primitive unhandled errors', async () => {
4546
await withBrowser(async (response, context) => {
4647
const page = await context.newPage();
47-
const issuePromise = new Promise<void>(resolve => {
48-
page.once('issue', () => {
49-
resolve();
50-
});
51-
});
52-
await page.setContent('<input type="text" name="username" />');
53-
await issuePromise;
48+
await page.setContent('<script>throw undefined;</script>');
5449
await listConsoleMessages.handler({params: {}}, response, context);
5550
const formattedResponse = await response.handle('test', context);
5651
const textContent = formattedResponse[0] as {text: string};
5752
assert.ok(
58-
textContent.text.includes(
59-
`msgid=1 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
60-
),
53+
textContent.text.includes('msgid=1 [error] undefined (0 args)'),
6154
);
6255
});
6356
});
6457

65-
it('lists issues after a page reload', async () => {
66-
await withBrowser(async (response, context) => {
67-
const page = await context.newPage();
68-
const issuePromise = new Promise<void>(resolve => {
69-
page.once('issue', () => {
70-
resolve();
58+
describe('issues', () => {
59+
beforeEach(() => {
60+
setIssuesEnabled(true);
61+
});
62+
afterEach(() => {
63+
setIssuesEnabled(false);
64+
});
65+
it('lists issues', async () => {
66+
await withBrowser(async (response, context) => {
67+
const page = await context.newPage();
68+
const issuePromise = new Promise<void>(resolve => {
69+
page.once('issue', () => {
70+
resolve();
71+
});
7172
});
72-
});
73-
74-
await page.setContent('<input type="text" name="username" />');
75-
await issuePromise;
76-
await listConsoleMessages.handler({params: {}}, response, context);
77-
{
73+
await page.setContent('<input type="text" name="username" />');
74+
await issuePromise;
75+
await listConsoleMessages.handler({params: {}}, response, context);
7876
const formattedResponse = await response.handle('test', context);
7977
const textContent = formattedResponse[0] as {text: string};
8078
assert.ok(
8179
textContent.text.includes(
8280
`msgid=1 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
8381
),
8482
);
85-
}
86-
87-
const anotherIssuePromise = new Promise<void>(resolve => {
88-
page.once('issue', () => {
89-
resolve();
90-
});
9183
});
92-
await page.reload();
93-
await page.setContent('<input type="text" name="username" />');
94-
await anotherIssuePromise;
95-
{
96-
const formattedResponse = await response.handle('test', context);
97-
const textContent = formattedResponse[0] as {text: string};
98-
assert.ok(
99-
textContent.text.includes(
100-
`msgid=2 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
101-
),
102-
);
103-
}
10484
});
105-
});
10685

107-
it('work with primitive unhandled errors', async () => {
108-
await withBrowser(async (response, context) => {
109-
const page = await context.newPage();
110-
await page.setContent('<script>throw undefined;</script>');
111-
await listConsoleMessages.handler({params: {}}, response, context);
112-
const formattedResponse = await response.handle('test', context);
113-
const textContent = formattedResponse[0] as {text: string};
114-
assert.ok(
115-
textContent.text.includes('msgid=1 [error] undefined (0 args)'),
116-
);
86+
it('lists issues after a page reload', async () => {
87+
await withBrowser(async (response, context) => {
88+
const page = await context.newPage();
89+
const issuePromise = new Promise<void>(resolve => {
90+
page.once('issue', () => {
91+
resolve();
92+
});
93+
});
94+
95+
await page.setContent('<input type="text" name="username" />');
96+
await issuePromise;
97+
await listConsoleMessages.handler({params: {}}, response, context);
98+
{
99+
const formattedResponse = await response.handle('test', context);
100+
const textContent = formattedResponse[0] as {text: string};
101+
assert.ok(
102+
textContent.text.includes(
103+
`msgid=1 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
104+
),
105+
);
106+
}
107+
108+
const anotherIssuePromise = new Promise<void>(resolve => {
109+
page.once('issue', () => {
110+
resolve();
111+
});
112+
});
113+
await page.reload();
114+
await page.setContent('<input type="text" name="username" />');
115+
await anotherIssuePromise;
116+
{
117+
const formattedResponse = await response.handle('test', context);
118+
const textContent = formattedResponse[0] as {text: string};
119+
assert.ok(
120+
textContent.text.includes(
121+
`msgid=2 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
122+
),
123+
);
124+
}
125+
});
117126
});
118127
});
119128
});

0 commit comments

Comments
 (0)