【问题标题】:Headless chrome proxy server settings无头 chrome 代理服务器设置
【发布时间】:2017-10-07 17:00:50
【问题描述】:

在使用 Node.js 中的灯塔 chrome 启动器时,任何人都可以帮我设置无头 chrome 的代理服务器,如提到的 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 使用它的任何示例。

【问题讨论】:

    标签: node.js google-chrome google-chrome-devtools headless-browser lighthouse


    【解决方案1】:

    我用普通的exec 试过了,效果很好,这是我的 sn-p:

    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 并在开发人员工具中看到:

    代理连接错误,没关系,因为我在这个端口上没有代理,但这意味着Chrome试图通过代理连接...

    顺便说一句,Chrome 版本是 59。

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

    我看这里没有additionalFlags,只有chromeFlags 尝试使用它...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-05
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多