feat(core): unify proxy; optimize request-wrapper (#11472)

* feat(core): unify proxy; optimize request-wrapper

Signed-off-by: Rongrong <i@rong.moe>

* Fix DeepScan issue

Signed-off-by: Rongrong <i@rong.moe>

* Simplify protocol existence judgment

Signed-off-by: Rongrong <i@rong.moe>

* chore: regenerate yarn.lock

Signed-off-by: Rongrong <i@rong.moe>
This commit is contained in:
Rongrong
2022-12-23 01:13:01 +08:00
committed by GitHub
parent 58d00a6917
commit d60d89ea87
7 changed files with 835 additions and 640 deletions

View File

@@ -1,4 +1,5 @@
const config = require('@/config').value;
const { proxyUri, proxyUrlHandler } = require('./unify-proxy');
let puppeteer = require('puppeteer');
const proxyChain = require('proxy-chain');
const logger = require('./logger');
@@ -9,13 +10,6 @@ const options = {
ignoreHTTPSErrors: true,
};
let proxyUri;
if (config.proxyUri && typeof config.proxyUri === 'string') {
proxyUri = config.proxyUri;
} else if (config.proxy && config.proxy.protocol && config.proxy.host && config.proxy.port) {
proxyUri = `${config.proxy.protocol}://${config.proxy.host}:${config.proxy.port}`;
}
/**
* @param {Object} extraOptions
* @param {boolean} extraOptions.stealth - Use puppeteer-extra-plugin-stealth
@@ -51,9 +45,9 @@ module.exports = async (extraOptions = {}) => {
}
let browser;
if (proxyUri) {
if (proxyUri.includes('@')) {
if (proxyUrlHandler.username || proxyUrlHandler.password) {
// only proxies with authentication need to be anonymized
if (proxyUri.startsWith('http:')) {
if (proxyUrlHandler.protocol === 'http:') {
options.args.push(`--proxy-server=${await proxyChain.anonymizeProxy(proxyUri)}`);
} else {
logger.warn('SOCKS/HTTPS proxy with authentication is not supported by puppeteer, continue without proxy');