在Google Chrome中传递基本身份验证凭据会再次显示弹出窗口

5

我正在使用watir(Ruby selenium软件包)尝试使用基本身份验证登录到url。

我像这样传递凭据:

 https://username:password@nagios.com

然而当浏览器打开时,我会弹出一个窗口要求重新输入凭据。
我使用的代码如下:
driver = Watir::Browser.new :chrome
driver.goto "https://username:password@nagios.com"

上述代码打开浏览器 -> 转到URL,但会弹出要求重新输入凭据的弹窗。
如何使用基本身份验证登录到URL?

什么浏览器?可能是该网站或驱动程序当前不支持基本身份验证。 - titusfortner
1个回答

8
Chrome在52版本之后停止支持通过URL传递凭据,更多信息请参见https://medium.com/@lmakarov/say-goodbye-to-urls-with-embedded-credentials-b051f6c7b6a3
为了解决这个问题,在启动浏览器时需要设置一个参数--disable-blink-features="BlockCredentialedSubresources"。它的作用是禁用此功能。
更多信息,请参见Bypass blocking of subresource requests whose URLs contain embedded credentials
这是我的最终可行代码。
 args = ['--disable-software-rasterizer',
                    '--disable-blink-features="BlockCredentialedSubresources"',
                    '--no-proxy-server',
                    '--disable-gpu',
                    '--no-sandbox',
                    '--ignore-certificate-errors']
driver = Watir::Browser.new :chrome, options: {args: args}
driver.goto "https://username:password@nagios.com"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接