Skip to content

Commit

Permalink
fix(install): respect environment proxy config when downloading Firef… (
Browse files Browse the repository at this point in the history
#6577)

Issues: #6573
  • Loading branch information
benelliott committed Sep 15, 2021
1 parent cb4470a commit 9399c97
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/api.md
Expand Up @@ -463,7 +463,7 @@ You will then need to call [`puppeteer.connect([options])`](#puppeteerconnectopt
Puppeteer looks for certain [environment variables](https://en.wikipedia.org/wiki/Environment_variable) to aid its operations.
If Puppeteer doesn't find them in the environment during the installation step, a lowercased variant of these variables will be used from the [npm config](https://docs.npmjs.com/cli/config).

- `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run Chromium.
- `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run the browser.
- `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.
Expand Down
29 changes: 25 additions & 4 deletions src/node/install.ts
Expand Up @@ -15,11 +15,16 @@
*/

import os from 'os';
import https from 'https';
import https, { RequestOptions } from 'https';
import ProgressBar from 'progress';
import URL from 'url';
import puppeteer from '../node.js';
import { PUPPETEER_REVISIONS } from '../revisions.js';
import { PuppeteerNode } from './Puppeteer.js';
import createHttpsProxyAgent, {
HttpsProxyAgentOptions,
} from 'https-proxy-agent';
import { getProxyForUrl } from 'proxy-from-env';

const supportedProducts = {
chrome: 'Chromium',
Expand Down Expand Up @@ -148,16 +153,32 @@ export async function downloadBrowser(): Promise<void> {
}

function getFirefoxNightlyVersion() {
const firefoxVersions =
const firefoxVersionsUrl =
'https://product-details.mozilla.org/1.0/firefox_versions.json';

const proxyURL = getProxyForUrl(firefoxVersionsUrl);

const requestOptions: RequestOptions = {};

if (proxyURL) {
const parsedProxyURL = URL.parse(proxyURL);

const proxyOptions = {
...parsedProxyURL,
secureProxy: parsedProxyURL.protocol === 'https:',
} as HttpsProxyAgentOptions;

requestOptions.agent = createHttpsProxyAgent(proxyOptions);
requestOptions.rejectUnauthorized = false;
}

const promise = new Promise((resolve, reject) => {
let data = '';
logPolitely(
`Requesting latest Firefox Nightly version from ${firefoxVersions}`
`Requesting latest Firefox Nightly version from ${firefoxVersionsUrl}`
);
https
.get(firefoxVersions, (r) => {
.get(firefoxVersionsUrl, requestOptions, (r) => {
if (r.statusCode >= 400)
return reject(new Error(`Got status code ${r.statusCode}`));
r.on('data', (chunk) => {
Expand Down

0 comments on commit 9399c97

Please sign in to comment.