From 3bf5a552890ee80cc4326b1e430424b0fdad4363 Mon Sep 17 00:00:00 2001 From: Dr Date: Thu, 26 Nov 2020 19:42:18 +0800 Subject: [PATCH] fix: update to https-proxy-agent@^5.0.0 to fix `ERR_INVALID_PROTOCOL` (#6555) With `nodejs@15.0.1`, install puppeteer with `https_proxy` set causes an error like: ``` > puppeteer@5.4.1 install node_modules/puppeteer > node install.js ERROR: Failed to set up Chromium r809590! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download. TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:" at new NodeError (node:internal/errors:258:15) at new ClientRequest (node:_http_client:155:11) at Object.request (node:https:313:10) at httpRequest (node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:488:17) at downloadFile (node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:357:21) at BrowserFetcher.download (node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:239:19) at async downloadBrowser (node_modules/puppeteer/lib/cjs/puppeteer/node/install.js:48:5) { code: 'ERR_INVALID_PROTOCOL' } ``` The related issue is at https://github.com/TooTallNate/node-agent-base/pull/47, from package `agent-base` under `https-proxy-agent` And the version bump is for `Refactor to TypeScript` is here: https://github.com/TooTallNate/node-https-proxy-agent/compare/4.0.0...5.0.0 --- package.json | 2 +- src/node/BrowserFetcher.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 482f799752ae1..18ff4d402690e 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "debug": "^4.1.0", "devtools-protocol": "0.0.818844", "extract-zip": "^2.0.0", - "https-proxy-agent": "^4.0.0", + "https-proxy-agent": "^5.0.0", "node-fetch": "^2.6.1", "pkg-dir": "^4.2.0", "progress": "^2.0.1", diff --git a/src/node/BrowserFetcher.ts b/src/node/BrowserFetcher.ts index 4653cd230c25d..7a90e4384a4a6 100644 --- a/src/node/BrowserFetcher.ts +++ b/src/node/BrowserFetcher.ts @@ -28,7 +28,10 @@ import { debug } from '../common/Debug.js'; import { promisify } from 'util'; import removeRecursive from 'rimraf'; import * as URL from 'url'; -import ProxyAgent from 'https-proxy-agent'; +import createHttpsProxyAgent, { + HttpsProxyAgent, + HttpsProxyAgentOptions, +} from 'https-proxy-agent'; import { getProxyForUrl } from 'proxy-from-env'; import { assert } from '../common/assert.js'; @@ -557,7 +560,7 @@ function httpRequest( type Options = Partial & { method?: string; - agent?: ProxyAgent; + agent?: HttpsProxyAgent; rejectUnauthorized?: boolean; }; @@ -581,9 +584,9 @@ function httpRequest( const proxyOptions = { ...parsedProxyURL, secureProxy: parsedProxyURL.protocol === 'https:', - } as ProxyAgent.HttpsProxyAgentOptions; + } as HttpsProxyAgentOptions; - options.agent = new ProxyAgent(proxyOptions); + options.agent = createHttpsProxyAgent(proxyOptions); options.rejectUnauthorized = false; } }