node.js – 无头镀铬代理服务器设置

任何人都可以帮我设置无头镀铬的代理服务器,同时在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中看到:

enter image description here

代理连接错误,这没关系,因为我没有此端口上的代理,但这意味着Chrome尝试通过代理连接…

BTW Chrome版本为59.

检查了源代码https://github.com/GoogleChrome/lighthouse/blob/master/chrome-launcher/chrome-launcher.ts#L38-L44

在这里看不到其他的标签,只有chromeFlags尝试使用它…

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...