Skip to content

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

chore(cli): fix install browser (#39280)

Pavel Feldman3f92471f07ea
diff --git a/packages/playwright/src/cli/client/program.ts b/packages/playwright/src/cli/client/program.ts
index 1db729dc53..780578f46d 100644
--- a/packages/playwright/src/cli/client/program.ts
+++ b/packages/playwright/src/cli/client/program.ts
@@ -180,6 +180,9 @@ async function program() {
case 'install':
await install(args);
return;
+ case 'install-browser':
+ await installBrowser();
+ return;
case 'show': {
const daemonScript = path.join(__dirname, 'devtoolsApp.js');
const child = spawn(process.execPath, [daemonScript], {
@@ -227,8 +230,7 @@ async function install(args: MinimistArgs) {
console.log(`✅ Skills installed to \`${path.relative(cwd, skillDestDir)}\`.`);
}
- if (!args.config)
- await ensureConfiguredBrowserInstalled();
+ await ensureConfiguredBrowserInstalled();
}
async function ensureConfiguredBrowserInstalled() {
@@ -251,6 +253,12 @@ async function ensureConfiguredBrowserInstalled() {
}
}
+async function installBrowser() {
+ const { program } = require('playwright-core/lib/cli/program');
+ const argv = process.argv.map(arg => arg === 'install-browser' ? 'install' : arg);
+ program.parse(argv);
+}
+
async function createDefaultConfig(channel: string) {
const config: Config = {
browser: {
diff --git a/packages/playwright/src/cli/daemon/commands.ts b/packages/playwright/src/cli/daemon/commands.ts
index 4259e24072..6fc435c7b1 100644
--- a/packages/playwright/src/cli/daemon/commands.ts
+++ b/packages/playwright/src/cli/daemon/commands.ts
@@ -844,8 +844,16 @@ const installBrowser = declareCommand({
name: 'install-browser',
description: 'Install browser',
category: 'install',
+ args: z.object({
+ browser: z.string().optional().describe('Browser to install'),
+ }),
options: z.object({
- browser: z.string().optional().describe('Browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge'),
+ ['with-deps']: z.boolean().optional().describe('Install system dependencies for browsers'),
+ ['dry-run']: z.boolean().optional().describe('Do not execute installation, only print information'),
+ list: z.boolean().optional().describe('Prints list of browsers from all Playwright installations'),
+ force: z.boolean().optional().describe('Force reinstall of already installed browsers'),
+ ['only-shell']: z.boolean().optional().describe('Only install headless shell when installing Chromium'),
+ ['no-shell']: z.boolean().optional().describe('Do not install Chromium headless shell'),
}),
toolName: 'browser_install',
toolParams: () => ({}),
diff --git a/tests/mcp/cli-misc.spec.ts b/tests/mcp/cli-misc.spec.ts
index 1b20c49e4a..96d43dbf78 100644
--- a/tests/mcp/cli-misc.spec.ts
+++ b/tests/mcp/cli-misc.spec.ts
@@ -29,9 +29,8 @@ test('daemon shuts down on browser launch failure', async ({ cli, server }) => {
test('install-browser', async ({ cli, server, mcpBrowser }) => {
test.skip(mcpBrowser !== 'chromium', 'Test only chromium');
- await cli('open', server.HELLO_WORLD);
- const { output } = await cli('install-browser');
- expect(output).toContain(`Browser ${mcpBrowser} installed.`);
+ const { output } = await cli('install-browser', '--list');
+ expect(output).toMatch(/chromium-\d+/);
});
test('install workspace', async ({ cli }, testInfo) => {