mirror of
https://github.com/ChromeDevTools/chrome-devtools-mcp.git
synced 2026-11-04 15:00:11 +00:00
refactor: disable issues in list_console_messages for now (#575)
Disabled the feature until the detail tool is ready.
This commit is contained in:
1 parent
305d7d7d9e
commit
08e9a9f42e
6 files changed
+110
-67
No files matched your search
@@ -16,6 +16,7 @@ import {
|
||||
} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
|
||||
|
||||
import {FakeIssuesManager} from './DevtoolsUtils.js';
|
||||
import {features} from './features.js';
|
||||
import {logger} from './logger.js';
|
||||
import type {
|
||||
CDPSession,
|
||||
@@ -231,6 +232,9 @@ export class ConsoleCollector extends PageCollector<
|
||||
|
||||
override addPage(page: Page): void {
|
||||
super.addPage(page);
|
||||
if (!features.issues) {
|
||||
return;
|
||||
}
|
||||
if (!this.#subscribedPages.has(page)) {
|
||||
const subscriber = new PageIssueSubscriber(page);
|
||||
this.#subscribedPages.set(page, subscriber);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
let issuesEnabled = false;
|
||||
|
||||
export const features = {
|
||||
get issues() {
|
||||
return issuesEnabled;
|
||||
},
|
||||
};
|
||||
|
||||
export function setIssuesEnabled(value: boolean) {
|
||||
issuesEnabled = value;
|
||||
}
|
||||
+4
-1
@@ -9,6 +9,7 @@ import './polyfill.js';
|
||||
import type {Channel} from './browser.js';
|
||||
import {ensureBrowserConnected, ensureBrowserLaunched} from './browser.js';
|
||||
import {parseArguments} from './cli.js';
|
||||
import {features} from './features.js';
|
||||
import {loadIssueDescriptions} from './issue-descriptions.js';
|
||||
import {logger, saveLogsToFile} from './logger.js';
|
||||
import {McpContext} from './McpContext.js';
|
||||
@@ -190,7 +191,9 @@ for (const tool of tools) {
|
||||
registerTool(tool);
|
||||
}
|
||||
|
||||
await loadIssueDescriptions();
|
||||
if (features.issues) {
|
||||
await loadIssueDescriptions();
|
||||
}
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
logger('Chrome DevTools MCP Server connected');
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {features} from '../features.js';
|
||||
import {zod} from '../third_party/index.js';
|
||||
import type {ConsoleMessageType} from '../third_party/index.js';
|
||||
|
||||
@@ -11,7 +12,7 @@ import {ToolCategory} from './categories.js';
|
||||
import {defineTool} from './ToolDefinition.js';
|
||||
type ConsoleResponseType = ConsoleMessageType | 'issue';
|
||||
|
||||
const FILTERABLE_MESSAGE_TYPES: readonly [
|
||||
const FILTERABLE_MESSAGE_TYPES: [
|
||||
ConsoleResponseType,
|
||||
...ConsoleResponseType[],
|
||||
] = [
|
||||
@@ -37,6 +38,10 @@ const FILTERABLE_MESSAGE_TYPES: readonly [
|
||||
'issue',
|
||||
];
|
||||
|
||||
if (features.issues) {
|
||||
FILTERABLE_MESSAGE_TYPES.push('issue');
|
||||
}
|
||||
|
||||
export const listConsoleMessages = defineTool({
|
||||
name: 'list_console_messages',
|
||||
description:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
import assert from 'node:assert';
|
||||
import {beforeEach, describe, it} from 'node:test';
|
||||
import {afterEach, beforeEach, describe, it} from 'node:test';
|
||||
|
||||
import type {
|
||||
Browser,
|
||||
@@ -17,6 +17,7 @@ import type {
|
||||
import sinon from 'sinon';
|
||||
|
||||
import {AggregatedIssue} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
|
||||
import {setIssuesEnabled} from '../src/features.js';
|
||||
import type {ListenerMap} from '../src/PageCollector.js';
|
||||
import {
|
||||
ConsoleCollector,
|
||||
@@ -357,6 +358,11 @@ describe('ConsoleCollector', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
setIssuesEnabled(true);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
setIssuesEnabled(false);
|
||||
});
|
||||
|
||||
it('emits issues on page', async () => {
|
||||
|
||||
+73
-64
@@ -4,8 +4,9 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
import assert from 'node:assert';
|
||||
import {before, describe, it} from 'node:test';
|
||||
import {afterEach, before, beforeEach, describe, it} from 'node:test';
|
||||
|
||||
import {setIssuesEnabled} from '../../src/features.js';
|
||||
import {loadIssueDescriptions} from '../../src/issue-descriptions.js';
|
||||
import {
|
||||
getConsoleMessage,
|
||||
@@ -41,69 +42,6 @@ describe('console', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('lists issues', async () => {
|
||||
await withBrowser(async (response, context) => {
|
||||
const page = await context.newPage();
|
||||
const issuePromise = new Promise<void>(resolve => {
|
||||
page.once('issue', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
await page.setContent('<input type="text" name="username" />');
|
||||
await issuePromise;
|
||||
await listConsoleMessages.handler({params: {}}, response, context);
|
||||
const formattedResponse = await response.handle('test', context);
|
||||
const textContent = formattedResponse[0] as {text: string};
|
||||
assert.ok(
|
||||
textContent.text.includes(
|
||||
`msgid=1 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('lists issues after a page reload', async () => {
|
||||
await withBrowser(async (response, context) => {
|
||||
const page = await context.newPage();
|
||||
const issuePromise = new Promise<void>(resolve => {
|
||||
page.once('issue', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
await page.setContent('<input type="text" name="username" />');
|
||||
await issuePromise;
|
||||
await listConsoleMessages.handler({params: {}}, response, context);
|
||||
{
|
||||
const formattedResponse = await response.handle('test', context);
|
||||
const textContent = formattedResponse[0] as {text: string};
|
||||
assert.ok(
|
||||
textContent.text.includes(
|
||||
`msgid=1 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const anotherIssuePromise = new Promise<void>(resolve => {
|
||||
page.once('issue', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
await page.reload();
|
||||
await page.setContent('<input type="text" name="username" />');
|
||||
await anotherIssuePromise;
|
||||
{
|
||||
const formattedResponse = await response.handle('test', context);
|
||||
const textContent = formattedResponse[0] as {text: string};
|
||||
assert.ok(
|
||||
textContent.text.includes(
|
||||
`msgid=2 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('work with primitive unhandled errors', async () => {
|
||||
await withBrowser(async (response, context) => {
|
||||
const page = await context.newPage();
|
||||
@@ -116,6 +54,77 @@ describe('console', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('issues', () => {
|
||||
beforeEach(() => {
|
||||
setIssuesEnabled(true);
|
||||
});
|
||||
afterEach(() => {
|
||||
setIssuesEnabled(false);
|
||||
});
|
||||
it('lists issues', async () => {
|
||||
await withBrowser(async (response, context) => {
|
||||
const page = await context.newPage();
|
||||
const issuePromise = new Promise<void>(resolve => {
|
||||
page.once('issue', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
await page.setContent('<input type="text" name="username" />');
|
||||
await issuePromise;
|
||||
await listConsoleMessages.handler({params: {}}, response, context);
|
||||
const formattedResponse = await response.handle('test', context);
|
||||
const textContent = formattedResponse[0] as {text: string};
|
||||
assert.ok(
|
||||
textContent.text.includes(
|
||||
`msgid=1 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('lists issues after a page reload', async () => {
|
||||
await withBrowser(async (response, context) => {
|
||||
const page = await context.newPage();
|
||||
const issuePromise = new Promise<void>(resolve => {
|
||||
page.once('issue', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
await page.setContent('<input type="text" name="username" />');
|
||||
await issuePromise;
|
||||
await listConsoleMessages.handler({params: {}}, response, context);
|
||||
{
|
||||
const formattedResponse = await response.handle('test', context);
|
||||
const textContent = formattedResponse[0] as {text: string};
|
||||
assert.ok(
|
||||
textContent.text.includes(
|
||||
`msgid=1 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const anotherIssuePromise = new Promise<void>(resolve => {
|
||||
page.once('issue', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
await page.reload();
|
||||
await page.setContent('<input type="text" name="username" />');
|
||||
await anotherIssuePromise;
|
||||
{
|
||||
const formattedResponse = await response.handle('test', context);
|
||||
const textContent = formattedResponse[0] as {text: string};
|
||||
assert.ok(
|
||||
textContent.text.includes(
|
||||
`msgid=2 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get_console_message', () => {
|
||||
|
||||
Reference in new issue
Block a user