Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"globals": "^17.0.0",
"lighthouse": "13.1.0",
"prettier": "^3.6.2",
"puppeteer": "24.41.0",
"puppeteer": "24.42.0",
"rollup": "4.60.2",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-license": "^3.6.0",
Expand Down
5 changes: 1 addition & 4 deletions scripts/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const nodeArgs = [
...files,
];

function installChrome(version) {
function _installChrome(version) {
try {
return execSync(
`npx puppeteer browsers install chrome@${version} --format "{{path}}"`,
Expand Down Expand Up @@ -112,9 +112,6 @@ async function runTests(attempt) {
});
}

const chromePath = installChrome('146.0.7680.31');
process.env.CHROME_M146_EXECUTABLE_PATH = chromePath;

const maxAttempts = shouldRetry ? 3 : 1;
let exitCode = 1;

Expand Down
36 changes: 12 additions & 24 deletions src/McpContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
SerializedAXNode,
Viewport,
Target,
Extension,
} from './third_party/index.js';
import type {DevTools} from './third_party/index.js';
import {Locator} from './third_party/index.js';
Expand All @@ -47,10 +48,6 @@ import type {
TextSnapshotNode,
ExtensionServiceWorker,
} from './types.js';
import {
ExtensionRegistry,
type InstalledExtension,
} from './utils/ExtensionRegistry.js';
import {ensureExtension, saveTemporaryFile} from './utils/files.js';
import {getNetworkMultiplierFromString} from './WaitForHelper.js';

Expand Down Expand Up @@ -83,7 +80,6 @@ export class McpContext implements Context {
#networkCollector: NetworkCollector;
#consoleCollector: ConsoleCollector;
#devtoolsUniverseManager: UniverseManager;
#extensionRegistry = new ExtensionRegistry();

#isRunningTrace = false;
#screenRecorderData: {recorder: ScreenRecorder; filePath: string} | null =
Expand Down Expand Up @@ -882,38 +878,30 @@ export class McpContext implements Context {

async installExtension(extensionPath: string): Promise<string> {
const id = await this.browser.installExtension(extensionPath);
await this.#extensionRegistry.registerExtension(id, extensionPath);
return id;
}

async uninstallExtension(id: string): Promise<void> {
await this.browser.uninstallExtension(id);
this.#extensionRegistry.remove(id);
}

async triggerExtensionAction(id: string): Promise<void> {
const page = this.getSelectedPptrPage();
// @ts-expect-error internal puppeteer api is needed since we don't have a way to get
// a tab id at the moment
const theTarget = page._tabId;
const session = await this.browser.target().createCDPSession();

try {
await session.send('Extensions.triggerAction', {
id,
targetId: theTarget,
});
} finally {
await session.detach();
const extensions = await this.browser.extensions();
const extension = extensions.get(id);
if (!extension) {
throw new Error(`Extension with ID ${id} not found.`);
}
const page = this.getSelectedPptrPage();
await extension.triggerAction(page);
}

listExtensions(): InstalledExtension[] {
return this.#extensionRegistry.list();
listExtensions(): Promise<Map<string, Extension>> {
return this.browser.extensions();
}

getExtension(id: string): InstalledExtension | undefined {
return this.#extensionRegistry.getById(id);
async getExtension(id: string): Promise<Extension | undefined> {
const pptrExtensions = await this.browser.extensions();
return pptrExtensions.get(id);
}

async getHeapSnapshotAggregates(
Expand Down
17 changes: 9 additions & 8 deletions src/McpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
ResourceType,
TextContent,
JSONSchema7Definition,
Extension,
} from './third_party/index.js';
import type {ToolGroup, ToolDefinition} from './tools/inPage.js';
import {handleDialog} from './tools/pages.js';
Expand All @@ -35,7 +36,6 @@ import type {
} from './tools/ToolDefinition.js';
import type {InsightName, TraceResult} from './trace-processing/parse.js';
import {getInsightOutput, getTraceSummary} from './trace-processing/parse.js';
import type {InstalledExtension} from './utils/ExtensionRegistry.js';
import {paginate} from './utils/pagination.js';
import type {PaginationOptions} from './utils/types.js';

Expand Down Expand Up @@ -527,9 +527,9 @@ export class McpResponse implements Response {
}
}

let extensions: InstalledExtension[] | undefined;
let extensions: Map<string, Extension> | undefined;
if (this.#listExtensions) {
extensions = context.listExtensions();
extensions = await context.listExtensions();
}

let inPageTools: ToolGroup<ToolDefinition> | undefined;
Expand Down Expand Up @@ -665,7 +665,7 @@ export class McpResponse implements Response {
networkRequests?: NetworkFormatter[];
traceSummary?: TraceResult;
traceInsight?: TraceInsightData;
extensions?: InstalledExtension[];
extensions?: Map<string, Extension>;
lighthouseResult?: LighthouseData;
inPageTools?: ToolGroup<ToolDefinition>;
webmcpTools?: WebMCPTool[];
Expand Down Expand Up @@ -947,14 +947,15 @@ Call ${handleDialog.name} to handle it before continuing.`);
}

if (data.extensions) {
structuredContent.extensions = data.extensions;
const extensionArray = Array.from(data.extensions.values());
structuredContent.extensions = extensionArray;
response.push('## Extensions');
if (data.extensions.length === 0) {
if (extensionArray.length === 0) {
response.push('No extensions installed.');
} else {
const extensionsMessage = data.extensions
const extensionsMessage = extensionArray
.map(extension => {
return `id=${extension.id} "${extension.name}" v${extension.version} ${extension.isEnabled ? 'Enabled' : 'Disabled'}`;
return `id=${extension.id} "${extension.name}" v${extension.version} ${extension.enabled ? 'Enabled' : 'Disabled'}`;
})
.join('\n');
response.push(extensionsMessage);
Expand Down
6 changes: 3 additions & 3 deletions src/tools/ToolDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {zod} from '../third_party/index.js';
import type {
Dialog,
ElementHandle,
Extension,
Page,
ScreenRecorder,
Viewport,
Expand All @@ -21,7 +22,6 @@ import type {
GeolocationOptions,
ExtensionServiceWorker,
} from '../types.js';
import type {InstalledExtension} from '../utils/ExtensionRegistry.js';
import type {PaginationOptions} from '../utils/types.js';

import type {ToolCategory} from './categories.js';
Expand Down Expand Up @@ -218,8 +218,8 @@ export type Context = Readonly<{
installExtension(path: string): Promise<string>;
uninstallExtension(id: string): Promise<void>;
triggerExtensionAction(id: string): Promise<void>;
listExtensions(): InstalledExtension[];
getExtension(id: string): InstalledExtension | undefined;
listExtensions(): Promise<Map<string, Extension>>;
getExtension(id: string): Promise<Extension | undefined>;
getSelectedMcpPage(): McpPage;
getExtensionServiceWorkers(): ExtensionServiceWorker[];
getExtensionServiceWorkerId(
Expand Down
2 changes: 1 addition & 1 deletion src/tools/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const reloadExtension = defineTool({
},
handler: async (request, response, context) => {
const {id} = request.params;
const extension = context.getExtension(id);
const extension = await context.getExtension(id);
if (!extension) {
throw new Error(`Extension with ID ${id} not found.`);
}
Expand Down
53 changes: 0 additions & 53 deletions src/utils/ExtensionRegistry.ts

This file was deleted.

4 changes: 2 additions & 2 deletions tests/McpResponse.test.js.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -1192,14 +1192,14 @@ exports[`extensions > lists extensions 2`] = `
"id": "id1",
"name": "Extension 1",
"version": "1.0",
"isEnabled": true,
"enabled": true,
"path": "/path/to/ext1"
},
{
"id": "id2",
"name": "Extension 2",
"version": "2.0",
"isEnabled": false,
"enabled": false,
"path": "/path/to/ext2"
}
]
Expand Down
46 changes: 29 additions & 17 deletions tests/McpResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import type {ParsedArguments} from '../src/bin/chrome-devtools-mcp-cli-options.j
import type {McpContext} from '../src/McpContext.js';
import type {McpResponse} from '../src/McpResponse.js';
import {replaceHtmlElementsWithUids} from '../src/McpResponse.js';
import type {JSONSchema7Definition} from '../src/third_party/index.js';
import type {
Extension,
JSONSchema7Definition,
} from '../src/third_party/index.js';
import {
closePage,
listPages,
Expand Down Expand Up @@ -955,22 +958,31 @@ describe('extensions', () => {

response.resetResponseLineForTesting();
// Testing with extensions
context.listExtensions = () => [
{
id: 'id1',
name: 'Extension 1',
version: '1.0',
isEnabled: true,
path: '/path/to/ext1',
},
{
id: 'id2',
name: 'Extension 2',
version: '2.0',
isEnabled: false,
path: '/path/to/ext2',
},
];
context.listExtensions = async () =>
Promise.resolve(
new Map<string, Extension>([
[
'id1',
{
id: 'id1',
name: 'Extension 1',
version: '1.0',
enabled: true,
path: '/path/to/ext1',
} as Extension,
],
[
'id2',
{
id: 'id2',
name: 'Extension 2',
version: '2.0',
enabled: false,
path: '/path/to/ext2',
} as Extension,
],
]),
);
response.setListExtensions();
const {content, structuredContent} = await response.handle(
'test',
Expand Down
Loading
Loading