有没有办法在Firefox的Puppeteer中使用代理? [英] Is there a way to use a proxy in Puppeteer for Firefox?
问题描述
是否可以将Puppeteer配置为在Firefox中使用代理,而无需手动调整操作系统的代理设置?
Is there a way to configure Puppeteer to use a proxy with Firefox, without manually having to adjust my operating system's proxy settings?
我可以通过使用命令行参数args: [ '--proxy-server=http://0.0.0.0:0000' ]
在Chrome中完成此操作,但是Firefox似乎没有此功能.
I am able to accomplish this in Chrome by using the command line argument args: [ '--proxy-server=http://0.0.0.0:0000' ]
, but Firefox doesn't seem to have this capability.
推荐答案
不幸的是,Firefox中没有'proxy-server'参数.
Unfortunately, there is no 'proxy-server' argument in Firefox.
但是,您可以拦截请求并使用 puppeteer-proxy 库设置代理
However, you can intercept the request and set a proxy with the puppeteer-proxy library.
这是一个示例.
import puppeteer from 'puppeteer';
import { proxyRequest } from 'puppeteer-proxy';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', async (request) => {
await proxyRequest({
page,
proxyUrl: 'http://127.0.0.1:3000',
request,
});
});
await page.goto('http://gajus.com');
})();
它也可以在Chrome和Firefox中使用.
It will work in Chrome and Firefox as well.
这篇关于有没有办法在Firefox的Puppeteer中使用代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!