mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(install): respect environment proxy config when downloading Firef… (#6577)
Issues: #6573
This commit is contained in:
parent
cb4470a6d9
commit
9399c9786f
@ -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.
|
||||
|
@ -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',
|
||||
@ -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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user