简体   繁体   English

chrome in --headless模式:为代理提供凭证/身份验证

[英]chrome in --headless mode: Provide credentials/auth for proxy

I am running chrome the following way: 我通过以下方式运行chrome:

google-chrome --headless --disable-gpu --dump-dom --disable-web-security

Due to a corporate proxy, it seems to be bumping into a authentication popup that is asking to input credentials. 由于公司代理,它似乎碰到要求输入凭据的身份验证弹出窗口。 How do I inject these credentials on the command line? 如何在命令行上注入这些凭据?

They is no direct way to do this. 他们没有直接的方法来做到这一点。 Google don't allow connection to a proxy with login/password in headless mode. Google不允许在无头模式下使用登录名/密码连接代理。

But, I was able to use proxy with credidential by using a MITMProxy. 但是,通过使用MITMProxy,我能够使用代理与credidential。 Other technology like Squid would work the same, but are more complicated to use. 像Squid这样的其他技术也会起作用,但使用起来会更复杂。

The trick is to create a local upstream proxy using MITMProxy that transferred your call through the real proxy you want to use. 诀窍是使用MITMProxy创建一个本地上游代理,通过您想要使用的真实代理转移您的呼叫。 MITMProxy do the autentification for you. MITMProxy为您进行autentification。

After installing MITMProxy, you can use it with the command line : 安装MITMProxy后,您可以在命令行中使用它:

~/mitmdump -p 9000 --mode upstream:http://proxy:port --set upstream_auth=login:password --ssl-insecure

You have to replace ~/mitmdump with your real path to mitmproxy (mitmdump will run it on your console). 您必须将〜/ mitmdump替换为mitmproxy的真实路径(mitmdump将在您的控制台上运行它)。 -p 9000 mean that MITMProxy is listening to http://localhost:9000 so you have to call this proxy with Chrome headless. -p 9000表示MITMProxy正在侦听http:// localhost:9000,因此您必须使用Chrome无头调用此代理。 --mode upstream will tell MITMProxy to redirect your traffic toward the real proxy you want to use. --mode upstream将告诉MITMProxy将您的流量重定向到您想要使用的真实代理。 --set upstream_auth allow you to connect with the right credidential. --set upstream_auth允许您连接正确的信用卡。 --ssl-insecure allow you to use https and ignore wrong certificate verification. --ssl-insecure允许您使用https并忽略错误的证书验证。

Then, you juste have to call chrome : 然后,你juste必须调用chrome:

google-chrome --headless --disable-gpu --dump-dom --disable-web-security --proxy-server=http://localhost:9000

Before beeing able to use it properly for https call, you have to import the MITMProxy security certificate with certutil: 在能够正确使用它进行https调用之前,您必须使用certutil导入MITMProxy安全证书:

certutil -d  sql:$HOME/.pki/nssdb -A -t "C,," -n mitm -i ~/.mitmproxy/mitmproxy-ca-cert.pem

If you have any trouble using this trick, MITMProxy have a well done documentation: https://mitmproxy.org/ 如果您在使用此技巧时遇到任何问题,MITMProxy会提供完善的文档: https ://mitmproxy.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM