Skip to content

Commit 9399c97

Browse files
authored
fix(install): respect environment proxy config when downloading Firef… (#6577)
Issues: #6573
1 parent cb4470a commit 9399c97

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

docs/api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ You will then need to call [`puppeteer.connect([options])`](#puppeteerconnectopt
463463
Puppeteer looks for certain [environment variables](https://en.wikipedia.org/wiki/Environment_variable) to aid its operations.
464464
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).
465465

466-
- `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run Chromium.
466+
- `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run the browser.
467467
- `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` - do not download bundled Chromium during installation step.
468468
- `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`.
469469
- `PUPPETEER_DOWNLOAD_PATH` - overwrite the path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is Puppeteer's package root.

src/node/install.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515
*/
1616

1717
import os from 'os';
18-
import https from 'https';
18+
import https, { RequestOptions } from 'https';
1919
import ProgressBar from 'progress';
20+
import URL from 'url';
2021
import puppeteer from '../node.js';
2122
import { PUPPETEER_REVISIONS } from '../revisions.js';
2223
import { PuppeteerNode } from './Puppeteer.js';
24+
import createHttpsProxyAgent, {
25+
HttpsProxyAgentOptions,
26+
} from 'https-proxy-agent';
27+
import { getProxyForUrl } from 'proxy-from-env';
2328

2429
const supportedProducts = {
2530
chrome: 'Chromium',
@@ -148,16 +153,32 @@ export async function downloadBrowser(): Promise<void> {
148153
}
149154

150155
function getFirefoxNightlyVersion() {
151-
const firefoxVersions =
156+
const firefoxVersionsUrl =
152157
'https://product-details.mozilla.org/1.0/firefox_versions.json';
153158

159+
const proxyURL = getProxyForUrl(firefoxVersionsUrl);
160+
161+
const requestOptions: RequestOptions = {};
162+
163+
if (proxyURL) {
164+
const parsedProxyURL = URL.parse(proxyURL);
165+
166+
const proxyOptions = {
167+
...parsedProxyURL,
168+
secureProxy: parsedProxyURL.protocol === 'https:',
169+
} as HttpsProxyAgentOptions;
170+
171+
requestOptions.agent = createHttpsProxyAgent(proxyOptions);
172+
requestOptions.rejectUnauthorized = false;
173+
}
174+
154175
const promise = new Promise((resolve, reject) => {
155176
let data = '';
156177
logPolitely(
157-
`Requesting latest Firefox Nightly version from ${firefoxVersions}`
178+
`Requesting latest Firefox Nightly version from ${firefoxVersionsUrl}`
158179
);
159180
https
160-
.get(firefoxVersions, (r) => {
181+
.get(firefoxVersionsUrl, requestOptions, (r) => {
161182
if (r.statusCode >= 400)
162183
return reject(new Error(`Got status code ${r.statusCode}`));
163184
r.on('data', (chunk) => {

0 commit comments

Comments
 (0)