Skip to content

Commit

Permalink
fix(launcher): output correct error message for browser (#6815)
Browse files Browse the repository at this point in the history
* 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 <mathias@qiwi.be>

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
  • Loading branch information
jackfranklin and mathiasbynens committed Feb 4, 2021
1 parent c936b18 commit 6c61874
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/node/Launcher.ts
Expand Up @@ -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) {
Expand All @@ -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 };
}
Expand Down

0 comments on commit 6c61874

Please sign in to comment.