fix: a pretty error when browser executable is not found (#3220)
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: 9132d23b2b/test/launcher.jest.js (L54-L59)
This doesn't test missing default browser installation which I think is
fine.
Fixes #3161
This commit is contained in:
parent
ae0c3a6d00
commit
e09132527d
|
|
@ -55,6 +55,7 @@ export interface BrowserType {
|
||||||
|
|
||||||
const mkdirAsync = util.promisify(fs.mkdir);
|
const mkdirAsync = util.promisify(fs.mkdir);
|
||||||
const mkdtempAsync = util.promisify(fs.mkdtemp);
|
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-');
|
const DOWNLOADS_FOLDER = path.join(os.tmpdir(), 'playwright_downloads-');
|
||||||
|
|
||||||
type WebSocketNotPipe = { webSocketRegex: RegExp, stream: 'stdout' | 'stderr' };
|
type WebSocketNotPipe = { webSocketRegex: RegExp, stream: 'stdout' | 'stderr' };
|
||||||
|
|
@ -190,6 +191,13 @@ export abstract class BrowserTypeBase implements BrowserType {
|
||||||
const executable = executablePath || this.executablePath();
|
const executable = executablePath || this.executablePath();
|
||||||
if (!executable)
|
if (!executable)
|
||||||
throw new Error(`No executable path is specified. Pass "executablePath" option directly.`);
|
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) {
|
if (!executablePath) {
|
||||||
// We can only validate dependencies for bundled browsers.
|
// We can only validate dependencies for bundled browsers.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue