From 6c618747979c3a08f2727e9e22fe45cade8c926a Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Thu, 4 Feb 2021 11:59:01 +0000 Subject: [PATCH] fix(launcher): output correct error message for browser (#6815) * fix(launcher): output correct error message for browser When running `npm run release` today I got this error logged: ``` Error: Could not find browser revision 848005. Run "PUPPETEER_PRODUCT=firefox npm install" or "PUPPETEER_PRODUCT=firefox yarn install" to download a supported Firefox browser binary. at ChromeLauncher.launch (/Users/jacktfranklin/src/puppeteer/lib/cjs/puppeteer/node/Launcher.js:80:27) ``` The error is only partially correct; I did have the browser revision missing, but I needed the Chromium browser, not Firefox. It turns out the logic in `Launcher.ts` didn't take this into account; it mistakenly had been hardcoded to always log out the error as if the Firefox binary was missing. This PR updates the message depending on the browser: Chrome error: > Error: Could not find expected browser (chrome) locally. Run npm > install or yarn install to download the correct Chromium revision > (848005). Firefox error: > Error: Could not find expected browser (firefox) locally. Run > "PUPPETEER_PRODUCT=firefox npm install" or "PUPPETEER_PRODUCT=firefox > yarn install" to download a supported Firefox browser binary. * Update src/node/Launcher.ts Co-authored-by: Mathias Bynens Co-authored-by: Mathias Bynens --- src/node/Launcher.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/node/Launcher.ts b/src/node/Launcher.ts index 2384deb9..bcfb28d5 100644 --- a/src/node/Launcher.ts +++ b/src/node/Launcher.ts @@ -615,6 +615,7 @@ function resolveExecutablePath( product: launcher.product, path: downloadPath, }); + if (!launcher._isPuppeteerCore && launcher.product === 'chrome') { const revision = process.env['PUPPETEER_CHROMIUM_REVISION']; if (revision) { @@ -627,8 +628,13 @@ function resolveExecutablePath( } } const revisionInfo = browserFetcher.revisionInfo(launcher._preferredRevision); + + const firefoxHelp = `Run \`PUPPETEER_PRODUCT=firefox npm install\` to download a supported Firefox browser binary.`; + const chromeHelp = `Run \`npm install\` to download the correct Chromium revision (${launcher._preferredRevision}).`; const missingText = !revisionInfo.local - ? `Could not find browser revision ${launcher._preferredRevision}. Run "PUPPETEER_PRODUCT=firefox npm install" or "PUPPETEER_PRODUCT=firefox yarn install" to download a supported Firefox browser binary.` + ? `Could not find expected browser (${launcher.product}) locally. ${ + launcher.product === 'chrome' ? chromeHelp : firefoxHelp + }` : null; return { executablePath: revisionInfo.executablePath, missingText }; }