我们使用Google Chrome运行集成测试。某些测试会下载文档,而该测试有时会不起作用。经过调查,我们发现Chrome阻止了我们的下载,这导致测试失败,因为它希望文件成功下载:
问题出现时,我们感到困惑,因为在我们的本地环境中测试是稳定的,而且从未失败。
我们为此问题创建了最小的可复制示例。它包含简单的python HTTP服务器,该服务器提供单个空文件document.xml
并返回下一个标头:
Content-type: application/xml
Content-disposition: attachment; filename=document.xml
当我们运行Google Chrome浏览器并尝试下载此文件时,它只是通过通知This type of file can harm your computer...
阻止了该过程。
如果我们尝试再次单击该链接,而不是Chrome 突然下载文件,而没有任何警告(您可以在屏幕截图中看到此信息)。
我们尝试使用命令行选项--safebrowsing-disable-download-protection
禁用此行为,并且尝试设置--safebrowsing.enabled=false
,但没有任何变化。
此外,我们尝试手动启用/禁用chrome://flags
中的某些标志:
#disallow-unsafe-http-downloads
-设置为“禁用” #allow-insecure-localhost
-设置为已启用但是情况还是一样。
此后,我们查看使用以下命令行设置报告的Chrome日志:--enable-logging -v=2
,但是没有直接的线索可以解决问题:
network_delegate.cc(32) NetworkDelegate::NotifyBeforeURLRequest: http://localhost:8000/document.xml
network_delegate.cc(32) NetworkDelegate::NotifyBeforeURLRequest: http://localhost:8000/document.xml
network_delegate.cc(32) NetworkDelegate::NotifyBeforeURLRequest: http://localhost:8000/document.xml
network_delegate.cc(32) NetworkDelegate::NotifyBeforeURLRequest: http://localhost:8000/document.xml
network_delegate.cc(32) NetworkDelegate::NotifyBeforeURLRequest: http://localhost:8000/document.xml
prescient_networking_dispatcher.cc(19) Prefetch DNS: localhost
prescient_networking_dispatcher.cc(19) Prefetch DNS: localhost
prescient_networking_dispatcher.cc(19) Prefetch DNS: localhost
loader_util.cc(45) To buffer: http://localhost:8000/document.xml
navigator_impl.cc(140) Failed Provisional Load: http://localhost:8000/document.xml, error_code: -3, error_description: The webpage at <strong jscontent="failedUrl"></strong> might be temporarily down or it may have moved permanently to a new web address., showing_repost_interstitial: 0, frame_id: 4
prescient_networking_dispatcher.cc(19) Prefetch DNS:
network_delegate.cc(32) NetworkDelegate::NotifyBeforeURLRequest: https://sb-ssl.google.com/safebrowsing/clientreport/download?key=[some key]
network_delegate.cc(32) NetworkDelegate::NotifyBeforeURLRequest: https://sb-ssl.google.com/safebrowsing/clientreport/download?key=[some key]
network_delegate.cc(32) NetworkDelegate::NotifyBeforeURLRequest: https://sb-ssl.google.com/safebrowsing/clientreport/download?key=[some key]
network_delegate.cc(32) NetworkDelegate::NotifyBeforeURLRequest: https://sb-ssl.google.com/safebrowsing/clientreport/download?key=[some key]
最后,我们遇到了Google Chrome浏览器的下载保护问题,该问题仅在首次尝试下载时有效。重新启动Chrome后可以重现该行为(注意:重新启动后用户数据首选项保持不变,因此这种奇怪的行为仅是由于Chrome内部状态引起的。)
有人能描述这种奇怪的Chrome行为并提出解决方案吗?
我们的配置:Google Chrome 69.0.3497.92
,Windows Server 2012 R2, version 6.3