|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
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 | + |
18 | 24 | import * as mcpServer from './sdk/server'; |
19 | 25 | import { commaSeparatedList, dotenvFileLoader, headerParser, numberParser, resolutionParser, resolveCLIConfig, semicolonSeparatedList } from './browser/config'; |
20 | 26 | import { setupExitWatchdog } from './browser/watchdog'; |
@@ -70,12 +76,21 @@ export function decorateCommand(command: Command, version: string) { |
70 | 76 | setupExitWatchdog(); |
71 | 77 |
|
72 | 78 | if (options.vision) { |
73 | | - // eslint-disable-next-line no-console |
74 | 79 | console.error('The --vision option is deprecated, use --caps=vision instead'); |
75 | 80 | options.caps = 'vision'; |
76 | 81 | } |
77 | 82 |
|
78 | 83 | 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 | + |
79 | 94 | const browserContextFactory = contextFactory(config); |
80 | 95 | const extensionContextFactory = new ExtensionContextFactory(config.browser.launchOptions.channel || 'chrome', config.browser.userDataDir, config.browser.launchOptions.executablePath); |
81 | 96 |
|
@@ -122,3 +137,12 @@ export function decorateCommand(command: Command, version: string) { |
122 | 137 | await mcpServer.start(factory, config.server); |
123 | 138 | }); |
124 | 139 | } |
| 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