Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(install): respect environment proxy config when downloading Firef… #6577

Merged
merged 5 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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