尝试使用 puppeteer 和 crawlera 代理服务器设置代理,但是当尝试设置 Proxy-Authenticate 标头时,它给出错误错误:net::ERR_INVALID_ARGUMENT。puppeteer 不支持该标题还是什么?这是我的代码示例
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const qs = require('qs');
const config = require('./config');
puppeteer.use(StealthPlugin());
module.exports = functions.https.onRequest(async (req, res) => {
// if(Math.random() < 0.35) {
// return res.send('not used')
// }
const message = {
params: {
category2_uid: '531770282580668418', // Web, Mobile & Software Dev
},
}
const options = {
headless: false,
args: ['--proxy-server=proxy.crawlera.com:8010'],
ignoreHTTPSErrors: true,
};
const browser = await puppeteer.launch(options);
try {
const page = await browser.newPage();
await page.setExtraHTTPHeaders({
'Proxy-Authenticate': 'Basic ' + Buffer.from(<Api_Key>:').toString('base64'),
});
await page.setJavaScriptEnabled(true);
await page.setCacheEnabled(true);
await page.setDefaultNavigationTimeout(0);
const navigationPromise = page.waitForNavigation({ timeout: 0 });
await page.goto('http://httpbin.org/get', {
waitUntil: ['networkidle2', 'domcontentloaded'],
});