Skip to content

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

fix(launcher): check for ffmpeg only when starting screencast (#3874)

Yury Semikhatskye5c6b19c00c1
diff --git a/src/server/chromium/videoRecorder.ts b/src/server/chromium/videoRecorder.ts
index 38e0df7dd4..5225883c93 100644
--- a/src/server/chromium/videoRecorder.ts
+++ b/src/server/chromium/videoRecorder.ts
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-import { launchProcess } from '../processLauncher';
import { ChildProcess } from 'child_process';
-import { Progress, ProgressController } from '../progress';
-import * as types from '../types';
-import * as path from 'path';
import * as os from 'os';
+import * as path from 'path';
import { assert } from '../../utils/utils';
+import { launchProcess } from '../processLauncher';
+import { Progress, ProgressController } from '../progress';
+import * as types from '../types';
+import { spawnAsync } from '../validateDependencies';
const fps = 25;
@@ -61,10 +62,16 @@ export class VideoRecorder {
let ffmpegPath = 'ffmpeg';
const binPath = path.join(__dirname, '../../../third_party/ffmpeg/');
- if (os.platform() === 'win32')
+ if (os.platform() === 'win32') {
ffmpegPath = path.join(binPath, os.arch() === 'x64' ? 'ffmpeg-win64.exe' : 'ffmpeg-win32.exe');
- else if (os.platform() === 'darwin')
+ } else if (os.platform() === 'darwin') {
ffmpegPath = path.join(binPath, 'ffmpeg-mac');
+ } else {
+ // Look for ffmpeg in PATH.
+ const {code, error} = await spawnAsync(ffmpegPath, ['-version'], {});
+ if (code !== 0 || error)
+ throw new Error('ffmpeg not found.\nInstall missing packages with:\n sudo apt-get install ffmpeg');
+ }
const { launchedProcess, gracefullyClose } = await launchProcess({
executablePath: ffmpegPath,
args,
diff --git a/src/server/validateDependencies.ts b/src/server/validateDependencies.ts
index 095d6d9465..23298ae542 100644
--- a/src/server/validateDependencies.ts
+++ b/src/server/validateDependencies.ts
@@ -115,8 +115,6 @@ async function validateDependenciesLinux(browserPath: string, browser: BrowserDe
}
for (const dep of (await missingDLOPENLibraries(browser)))
missingDeps.add(dep);
- for (const dep of (await missingSystemBinaries(browser)))
- missingDeps.add(dep);
if (!missingDeps.size)
return;
// Check Ubuntu version.
@@ -236,17 +234,7 @@ async function missingDLOPENLibraries(browser: BrowserDescriptor): Promise<strin
return libraries.filter(library => !isLibraryAvailable(library));
}
-async function missingSystemBinaries(browser: BrowserDescriptor): Promise<string[]> {
- if (browser.name !== 'chromium')
- return [];
- // Look for ffmpeg in PATH.
- const {code, error} = await spawnAsync('ffmpeg', ['-version'], {});
- if (code !== 0 || error)
- return ['ffmpeg'];
- return [];
-}
-
-function spawnAsync(cmd: string, args: string[], options: any): Promise<{stdout: string, stderr: string, code: number, error?: Error}> {
+export function spawnAsync(cmd: string, args: string[], options: any): Promise<{stdout: string, stderr: string, code: number, error?: Error}> {
const process = spawn(cmd, args, options);
return new Promise(resolve => {
@@ -439,6 +427,4 @@ const MANUAL_LIBRARY_TO_PACKAGE_NAME_UBUNTU: { [s: string]: string} = {
// and if it's missing recommend installing missing gstreamer lib.
// gstreamer1.0-libav -> libavcodec57 -> libx264-152
'libx264.so': 'gstreamer1.0-libav',
- // Required for screencast in Chromium.
- 'ffmpeg': 'ffmpeg',
};