alp*_*cod 7 google-chrome node.js headless-browser lighthouse google-chrome-devtools
任何人都可以帮我设置无头镀铬的代理服务器,同时在这里提到Node.js中的灯塔镀铬启动器
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' : ''
]
});
Run Code Online (Sandbox Code Playgroud)
但是,上面的脚本根本没有命中我的代理服务器.Chrome似乎回退到DIRECT://与目标网站的连接.
关于在无头chrome的上下文中使用HTTP/HTTPS代理服务器的另一个资源就是这个.但它没有给出如何从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)
});
Run Code Online (Sandbox Code Playgroud)
然后我导航到http:// localhost:9222并在Developer Tools中看到:

代理连接错误,这没关系,因为我没有此端口上的代理,但这意味着Chrome尝试通过代理连接...
BTW Chrome版本为59.
已检查源代码https://github.com/GoogleChrome/lighthouse/blob/master/chrome-launcher/chrome-launcher.ts#L38-L44
我additionalFlags在这里看不到,只有chromeFlags尝试使用它...
| 归档时间: |
|
| 查看次数: |
5286 次 |
| 最近记录: |