From 2367039a2c1e4bf64c181ccbec4a4543f4604930 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 18 Mar 2021 10:19:44 +0800 Subject: [PATCH] chore(stable): throw user-friendly message when ffmpeg is missing (#5865) --- src/server/chromium/crPage.ts | 18 +++++++++++++++++- src/server/chromium/findChromiumChannel.ts | 18 +++--------------- src/server/processLauncher.ts | 4 ++-- src/utils/utils.ts | 12 ++++++++++++ test/defaultbrowsercontext-2.spec.ts | 3 ++- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/server/chromium/crPage.ts b/src/server/chromium/crPage.ts index a9446ab1e8181..3ea29466aaa77 100644 --- a/src/server/chromium/crPage.ts +++ b/src/server/chromium/crPage.ts @@ -36,7 +36,7 @@ import { CRBrowserContext } from './crBrowser'; import * as types from '../types'; import { ConsoleMessage } from '../console'; import { rewriteErrorMessage } from '../../utils/stackTrace'; -import { assert, headersArrayToObject, createGuid } from '../../utils/utils'; +import { assert, headersArrayToObject, createGuid, canAccessFile } from '../../utils/utils'; import { VideoRecorder } from './videoRecorder'; @@ -816,6 +816,22 @@ class FrameSession { const ffmpegPath = this._crPage._browserContext._browser.options.registry.executablePath('ffmpeg'); if (!ffmpegPath) throw new Error('ffmpeg executable was not found'); + if (!canAccessFile(ffmpegPath)) { + let message: string = ''; + switch (this._page._browserContext._options.sdkLanguage) { + case 'python': message = 'playwright install ffmpeg'; break; + case 'python-async': message = 'playwright install ffmpeg'; break; + case 'javascript': message = 'npx playwright install ffmpeg'; break; + case 'java': message = 'mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="install ffmpeg"'; break; + } + throw new Error(` +============================================================ + Please install ffmpeg in order to record video. + + $ ${message} +============================================================ + `); + } this._videoRecorder = await VideoRecorder.launch(this._crPage._page, ffmpegPath, options); this._screencastId = screencastId; const gotFirstFrame = new Promise(f => this._client.once('Page.screencastFrame', f)); diff --git a/src/server/chromium/findChromiumChannel.ts b/src/server/chromium/findChromiumChannel.ts index 82df79d23e938..654820352ee1f 100644 --- a/src/server/chromium/findChromiumChannel.ts +++ b/src/server/chromium/findChromiumChannel.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import fs from 'fs'; import path from 'path'; +import { canAccessFile } from '../../utils/utils'; function darwin(channel: string): string | undefined { switch (channel) { @@ -60,24 +60,12 @@ function win32(channel: string): string | undefined { let result: string | undefined; prefixes.forEach(prefix => { const chromePath = path.join(prefix, suffix!); - if (canAccess(chromePath)) + if (canAccessFile(chromePath)) result = chromePath; }); return result; } -function canAccess(file: string) { - if (!file) - return false; - - try { - fs.accessSync(file); - return true; - } catch (e) { - return false; - } -} - export function findChromiumChannel(channel: string): string { let result: string | undefined; if (process.platform === 'linux') @@ -90,7 +78,7 @@ export function findChromiumChannel(channel: string): string { if (!result) throw new Error(`Chromium distribution '${channel}' is not supported on ${process.platform}`); - if (canAccess(result)) + if (canAccessFile(result)) return result; throw new Error(`Chromium distribution was not found: ${channel}`); } diff --git a/src/server/processLauncher.ts b/src/server/processLauncher.ts index 60835c374c753..c05a60d95d92e 100644 --- a/src/server/processLauncher.ts +++ b/src/server/processLauncher.ts @@ -86,7 +86,7 @@ export async function launchProcess(options: LaunchProcessOptions): Promise void; const failedPromise = new Promise((f, r) => failed = f); spawnedProcess.once('error', error => { - failed(new Error('Failed to launch browser: ' + error)); + failed(new Error('Failed to launch: ' + error)); }); return cleanup().then(() => failedPromise).then(e => Promise.reject(e)); } @@ -164,7 +164,7 @@ export async function launchProcess(options: LaunchProcessOptions): Promise { await browserContext3.close(); }); -it('should restore cookies from userDataDir', (test, { browserName }) => { +it('should restore cookies from userDataDir', (test, { platform, browserChannel }) => { test.slow(); + test.fixme(platform === 'win32' && browserChannel === 'chrome'); }, async ({browserType, browserOptions, server, createUserDataDir}) => { const userDataDir = await createUserDataDir(); const browserContext = await browserType.launchPersistentContext(userDataDir, browserOptions);