Skip to content
Merged
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
28 changes: 26 additions & 2 deletions packages/playwright/src/mcp/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
* limitations under the License.
*/

import { ProgramOption } from 'playwright-core/lib/utilsBundle';
/* eslint-disable no-console */

import fs from 'fs';

import { colors, ProgramOption } from 'playwright-core/lib/utilsBundle';
import { registry } from 'playwright-core/lib/server';

import * as mcpServer from './sdk/server';
import { commaSeparatedList, dotenvFileLoader, headerParser, numberParser, resolutionParser, resolveCLIConfig, semicolonSeparatedList } from './browser/config';
import { setupExitWatchdog } from './browser/watchdog';
Expand Down Expand Up @@ -70,12 +76,21 @@ export function decorateCommand(command: Command, version: string) {
setupExitWatchdog();

if (options.vision) {
// eslint-disable-next-line no-console
console.error('The --vision option is deprecated, use --caps=vision instead');
options.caps = 'vision';
}

const config = await resolveCLIConfig(options);

// Chromium browsers require ffmpeg to be installed to save video.
if (config.saveVideo && !checkFfmpeg()) {
console.error(colors.red(`\nError: ffmpeg required to save the video is not installed.`));
console.error(`\nPlease run the command below. It will install a local copy of ffmpeg and will not change any system-wide settings.`);
console.error(`\n npx playwright install ffmpeg\n`);
// eslint-disable-next-line no-restricted-properties

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note about the directory where to run the command?

process.exit(1);
}

const browserContextFactory = contextFactory(config);
const extensionContextFactory = new ExtensionContextFactory(config.browser.launchOptions.channel || 'chrome', config.browser.userDataDir, config.browser.launchOptions.executablePath);

Expand Down Expand Up @@ -122,3 +137,12 @@ export function decorateCommand(command: Command, version: string) {
await mcpServer.start(factory, config.server);
});
}

function checkFfmpeg(): boolean {
try {
const executable = registry.findExecutable('ffmpeg')!;
return fs.existsSync(executable.executablePath('javascript')!);
} catch (error) {
return false;
}
}
Loading