Skip to content

Commit

Permalink
fix: update to https-proxy-agent@^5.0.0 to fix ERR_INVALID_PROTOCOL (
Browse files Browse the repository at this point in the history
…#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 TooTallNate/node-agent-base#47, from package `agent-base` under `https-proxy-agent`

And the version bump is for `Refactor to TypeScript` is here: TooTallNate/proxy-agents@4.0.0...5.0.0
  • Loading branch information
dr-js committed Nov 26, 2020
1 parent 470124f commit 3bf5a55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions src/node/BrowserFetcher.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -557,7 +560,7 @@ function httpRequest(

type Options = Partial<URL.UrlWithStringQuery> & {
method?: string;
agent?: ProxyAgent;
agent?: HttpsProxyAgent;
rejectUnauthorized?: boolean;
};

Expand All @@ -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;
}
}
Expand Down

0 comments on commit 3bf5a55

Please sign in to comment.