任何人都可以帮我设置无头镀铬的代理服务器,同时在Node.js中使用灯塔镀铬启动器,如上所述
here
const launcher = new ChromeLauncher({ port: 9222,autoSelectChrome: true,// False to manually select which Chrome install. additionalFlags: [ '--window-size=412,732','--disable-gpu','--proxy-server="IP:PORT"',headless ? '--headless' : '' ] });
但是,上面的脚本根本没有命中我的代理服务器. Chrome似乎回退到DIRECT://与目标网站的连接.
在无头chrome的上下文中讨论使用HTTP / HTTPS代理服务器的另一个资源是this.但它没有给出如何从Node.js使用它的任何示例.
解决方法
我尝试使用常规exec,它工作得很好,这是我的片段:
const exec = require('child_process').exec; function launchHeadlessChrome(url,callback) { // Assuming MacOSx. const CHROME = '/Users/h0x91b/Desktop/Google\\ Chrome\\ Beta.app/Contents/MacOS/Google\\ Chrome'; exec(`${CHROME} --headless --disable-gpu --remote-debugging-port=9222 --proxy-server=127.0.0.1:8888 ${url}`,callback); } launchHeadlessChrome('https://www.chromestatus.com',(err,stdout,stderr) => { console.log('callback',err,stderr,stdout) });
然后我导航到http://localhost:9222并在Developer Tools中看到:
代理连接错误,这没关系,因为我没有此端口上的代理,但这意味着Chrome尝试通过代理连接…
BTW Chrome版本为59.
检查了源代码https://github.com/GoogleChrome/lighthouse/blob/master/chrome-launcher/chrome-launcher.ts#L38-L44