Skip to content

Commit

Permalink
fix: a pretty error when browser executable is not found (#3220)
Browse files Browse the repository at this point in the history
Make sure executable exists before launching it. If it doesn't and
we were launched without custom executable path, print a helpful
instruction to run `npm i playwright` and get browsers downloaded.

Note: there's already a test that makes sure bad executable paths
are treated fairly: https://github.com/microsoft/playwright/blob/9132d23b2bfadfcf46461f2135c37d9689d91033/test/launcher.jest.js#L54-L59

This doesn't test missing default browser installation which I think is
fine.

Fixes #3161
  • Loading branch information
aslushnikov authored Jul 30, 2020
1 parent ae0c3a6 commit e091325
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/server/browserType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface BrowserType {

const mkdirAsync = util.promisify(fs.mkdir);
const mkdtempAsync = util.promisify(fs.mkdtemp);
const existsAsync = (path: string): Promise<boolean> => new Promise(resolve => fs.stat(path, err => resolve(!err)));
const DOWNLOADS_FOLDER = path.join(os.tmpdir(), 'playwright_downloads-');

type WebSocketNotPipe = { webSocketRegex: RegExp, stream: 'stdout' | 'stderr' };
Expand Down Expand Up @@ -190,6 +191,13 @@ export abstract class BrowserTypeBase implements BrowserType {
const executable = executablePath || this.executablePath();
if (!executable)
throw new Error(`No executable path is specified. Pass "executablePath" option directly.`);
if (!(await existsAsync(executable))) {
const errorMessageLines = [`Failed to launch ${this._name} because executable doesn't exist at ${executable}`];
// If we tried using stock downloaded browser, suggest re-installing playwright.
if (!executablePath)
errorMessageLines.push(`Try re-installing playwright with "npm install playwright"`);
throw new Error(errorMessageLines.join('\n'));
}

if (!executablePath) {
// We can only validate dependencies for bundled browsers.
Expand Down

0 comments on commit e091325

Please sign in to comment.