Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat(cli): add install command (#39061)

Yury Semikhatsky809c345b8246
diff --git a/packages/playwright/src/mcp/browser/tools/install.ts b/packages/playwright/src/mcp/browser/tools/install.ts
index 23277b0f88..cfeb3099e6 100644
--- a/packages/playwright/src/mcp/browser/tools/install.ts
+++ b/packages/playwright/src/mcp/browser/tools/install.ts
@@ -48,6 +48,7 @@ const install = defineTool({
reject(new Error(`Failed to install browser: ${output.join('')}`));
});
});
+ response.addTextResult(`Browser ${channel} installed.`);
const tabHeaders = await Promise.all(context.tabs().map(tab => tab.headerSnapshot()));
const result = renderTabsMarkdown(tabHeaders);
response.addTextResult(result.join('\n'));
diff --git a/packages/playwright/src/mcp/terminal/command.ts b/packages/playwright/src/mcp/terminal/command.ts
index 100d924f0d..b45b10b7b9 100644
--- a/packages/playwright/src/mcp/terminal/command.ts
+++ b/packages/playwright/src/mcp/terminal/command.ts
@@ -18,7 +18,7 @@ import { z } from 'playwright-core/lib/mcpBundle';
import type zodType from 'zod';
-export type Category = 'core' | 'navigation' | 'keyboard' | 'mouse' | 'export' | 'storage' | 'tabs' | 'devtools' | 'session' | 'config';
+export type Category = 'core' | 'navigation' | 'keyboard' | 'mouse' | 'export' | 'storage' | 'tabs' | 'devtools' | 'session' | 'config' | 'install';
export type CommandSchema<Args extends zodType.ZodTypeAny, Options extends zodType.ZodTypeAny> = {
name: string;
diff --git a/packages/playwright/src/mcp/terminal/commands.ts b/packages/playwright/src/mcp/terminal/commands.ts
index ba6fdf634b..1bf0be76df 100644
--- a/packages/playwright/src/mcp/terminal/commands.ts
+++ b/packages/playwright/src/mcp/terminal/commands.ts
@@ -542,6 +542,17 @@ const config = declareCommand({
toolParams: () => ({}),
});
+const install = declareCommand({
+ name: 'install',
+ description: 'Install browser',
+ category: 'install',
+ options: z.object({
+ browser: z.string().optional().describe('Browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge'),
+ }),
+ toolName: 'browser_install',
+ toolParams: () => ({}),
+});
+
const commandsArray: AnyCommandSchema[] = [
// core category
open,
@@ -590,9 +601,12 @@ const commandsArray: AnyCommandSchema[] = [
tabClose,
tabSelect,
- // config
+ // config category
config,
+ // install category
+ install,
+
// devtools category
networkRequests,
tracingStart,
diff --git a/packages/playwright/src/mcp/terminal/helpGenerator.ts b/packages/playwright/src/mcp/terminal/helpGenerator.ts
index 72a4a762f6..17f1eb7ed0 100644
--- a/packages/playwright/src/mcp/terminal/helpGenerator.ts
+++ b/packages/playwright/src/mcp/terminal/helpGenerator.ts
@@ -72,6 +72,7 @@ const categories: { name: Category, title: string }[] = [
{ name: 'tabs', title: 'Tabs' },
{ name: 'storage', title: 'Storage' },
{ name: 'devtools', title: 'DevTools' },
+ { name: 'install', title: 'Install' },
{ name: 'config', title: 'Configuration' },
{ name: 'session', title: 'Sessions' },
] as const;
diff --git a/tests/mcp/cli.spec.ts b/tests/mcp/cli.spec.ts
index e1a993fefe..2b249ab968 100644
--- a/tests/mcp/cli.spec.ts
+++ b/tests/mcp/cli.spec.ts
@@ -667,3 +667,12 @@ test.describe('browser launch failure', () => {
expect(second.output).toContain('Page URL');
});
});
+
+test.describe('install', () => {
+ test('install', async ({ cli, server, mcpBrowser }) => {
+ test.skip(mcpBrowser !== 'chromium', 'Test only chromium');
+ await cli('open', server.HELLO_WORLD);
+ const { output } = await cli('install');
+ expect(output).toContain(`Browser ${mcpBrowser} installed.`);
+ });
+});