Skip to content

Commit 3b96851

Browse files
committed
chore: ensure ffmpeg is installed when saving video
1 parent 2686c09 commit 3b96851

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

packages/playwright/src/mcp/program.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ProgramOption } from 'playwright-core/lib/utilsBundle';
17+
/* eslint-disable no-console */
18+
19+
import fs from 'fs';
20+
21+
import { colors, ProgramOption } from 'playwright-core/lib/utilsBundle';
22+
import { registry } from 'playwright-core/lib/server';
23+
1824
import * as mcpServer from './sdk/server';
1925
import { commaSeparatedList, dotenvFileLoader, headerParser, numberParser, resolutionParser, resolveCLIConfig, semicolonSeparatedList } from './browser/config';
2026
import { setupExitWatchdog } from './browser/watchdog';
@@ -70,12 +76,21 @@ export function decorateCommand(command: Command, version: string) {
7076
setupExitWatchdog();
7177

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

7883
const config = await resolveCLIConfig(options);
84+
85+
// Chromium browsers require ffmpeg to be installed to save video.
86+
if (config.saveVideo && !checkFfmpeg()) {
87+
console.error(colors.red(`\nError: ffmpeg required to save the video is not installed.`));
88+
console.error(`\nPlease run the command below. It will install a local copy of ffmpeg and will not change any system-wide settings.`);
89+
console.error(`\n npx playwright install ffmpeg\n`);
90+
// eslint-disable-next-line no-restricted-properties
91+
process.exit(1);
92+
}
93+
7994
const browserContextFactory = contextFactory(config);
8095
const extensionContextFactory = new ExtensionContextFactory(config.browser.launchOptions.channel || 'chrome', config.browser.userDataDir, config.browser.launchOptions.executablePath);
8196

@@ -122,3 +137,12 @@ export function decorateCommand(command: Command, version: string) {
122137
await mcpServer.start(factory, config.server);
123138
});
124139
}
140+
141+
function checkFfmpeg(): boolean {
142+
try {
143+
const executable = registry.findExecutable('ffmpeg')!;
144+
return fs.existsSync(executable.executablePath('javascript')!);
145+
} catch (error) {
146+
return false;
147+
}
148+
}

0 commit comments

Comments
 (0)