Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: support configuring the browser download path (#6014)
By adding support for an environment variable `PUPPETEER_DOWNLOAD_PATH` it is possible to support downloading the browser binaries into a folder outside the `node_modules` folder. This makes it possible to preserve previously downloaded binaries in order to skip downloading them again.
  • Loading branch information
lcabral37 committed Aug 10, 2020
1 parent 615cd37 commit 13ea347
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/api.md
Expand Up @@ -411,6 +411,7 @@ If Puppeteer doesn't find them in the environment during the installation step,
- `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run Chromium.
- `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` - do not download bundled Chromium during installation step.
- `PUPPETEER_DOWNLOAD_HOST` - overwrite URL prefix that is used to download Chromium. Note: this includes protocol and might even include path prefix. Defaults to `https://storage.googleapis.com`.
- `PUPPETEER_DOWNLOAD_PATH` - overwrite the path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is puppeteer's package root.
- `PUPPETEER_CHROMIUM_REVISION` - specify a certain version of Chromium you'd like Puppeteer to use. See [puppeteer.launch([options])](#puppeteerlaunchoptions) on how executable path is inferred. **BEWARE**: Puppeteer is only [guaranteed to work](https://github.com/puppeteer/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk.
- `PUPPETEER_EXECUTABLE_PATH` - specify an executable path to be used in `puppeteer.launch`. See [puppeteer.launch([options])](#puppeteerlaunchoptions) on how the executable path is inferred. **BEWARE**: Puppeteer is only [guaranteed to work](https://github.com/puppeteer/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk.
- `PUPPETEER_PRODUCT` - specify which browser you'd like Puppeteer to use. Must be one of `chrome` or `firefox`. This can also be used during installation to fetch the recommended browser binary. Setting `product` programmatically in [puppeteer.launch([options])](#puppeteerlaunchoptions) supersedes this environment variable. The product is exposed in [`puppeteer.product`](#puppeteerproduct)
Expand Down
3 changes: 2 additions & 1 deletion experimental/puppeteer-firefox/install.js
Expand Up @@ -20,9 +20,10 @@ if (require('./package.json').name === 'puppeteer-core')
return;

const downloadHost = process.env.PUPPETEER_DOWNLOAD_HOST || process.env.npm_config_puppeteer_download_host || process.env.npm_package_config_puppeteer_download_host;
const downloadPath = process.env.PUPPETEER_DOWNLOAD_PATH || process.env.npm_config_puppeteer_download_path || process.env.npm_package_config_puppeteer_download_path;

const puppeteer = require('./index');
const browserFetcher = puppeteer.createBrowserFetcher({ host: downloadHost, product: 'firefox' });
const browserFetcher = puppeteer.createBrowserFetcher({ host: downloadHost, product: 'firefox', path: downloadPath });

const revision = require('./package.json').puppeteer.firefox_revision;

Expand Down
5 changes: 4 additions & 1 deletion experimental/puppeteer-firefox/lib/Launcher.js
Expand Up @@ -231,7 +231,10 @@ class Launcher {
}

_resolveExecutablePath() {
const browserFetcher = new BrowserFetcher(this._projectRoot, { product: 'firefox' });
const downloadPath = process.env.PUPPETEER_DOWNLOAD_PATH ||
process.env.npm_config_puppeteer_download_path ||
process.env.npm_package_config_puppeteer_download_path;
const browserFetcher = new BrowserFetcher(this._projectRoot, { product: 'firefox', path: downloadPath });
const revisionInfo = browserFetcher.revisionInfo(this._preferredRevision);
const missingText = !revisionInfo.local ? `Firefox revision is not downloaded. Run "npm install" or "yarn install"` : null;
return {executablePath: revisionInfo.executablePath, missingText};
Expand Down
5 changes: 5 additions & 0 deletions src/install.ts
Expand Up @@ -35,9 +35,14 @@ export async function downloadBrowser() {
process.env.npm_config_puppeteer_product ||
process.env.npm_package_config_puppeteer_product ||
'chrome';
const downloadPath =
process.env.PUPPETEER_DOWNLOAD_PATH ||
process.env.npm_config_puppeteer_download_path ||
process.env.npm_package_config_puppeteer_download_path;
const browserFetcher = puppeteer.createBrowserFetcher({
product,
host: downloadHost,
path: downloadPath,
});
const revision = await getRevision();
await fetchBinary(revision);
Expand Down
6 changes: 6 additions & 0 deletions src/node/Launcher.ts
Expand Up @@ -744,6 +744,7 @@ function getWSEndpoint(browserURL: string): Promise<string> {
function resolveExecutablePath(
launcher: ChromeLauncher | FirefoxLauncher
): { executablePath: string; missingText?: string } {
let downloadPath: string;
// puppeteer-core doesn't take into account PUPPETEER_* env variables.
if (!launcher._isPuppeteerCore) {
const executablePath =
Expand All @@ -757,9 +758,14 @@ function resolveExecutablePath(
: null;
return { executablePath, missingText };
}
downloadPath =
process.env.PUPPETEER_DOWNLOAD_PATH ||
process.env.npm_config_puppeteer_download_path ||
process.env.npm_package_config_puppeteer_download_path;
}
const browserFetcher = new BrowserFetcher(launcher._projectRoot, {
product: launcher.product,
path: downloadPath,
});
if (!launcher._isPuppeteerCore && launcher.product === 'chrome') {
const revision = process.env['PUPPETEER_CHROMIUM_REVISION'];
Expand Down

0 comments on commit 13ea347

Please sign in to comment.