无头chrome不会发送Accept-Language标头

时间:2018-03-29 10:26:16

标签: http-headers fiddler google-chrome-headless http-accept-language

在测试无头chrome时,我注意到它没有传输Accept-Language标头条目。我已经确认,当有可见的浏览器窗口时它会被发送。

这是否有原因并且Chrome是否有选项要求/强制它发送这些正常值?

要看到这一点,你可以启动Fiddler并在命令行输入:

chrome --headless --incognito --window-size=1920,1080 --disable-gpu --no-sandbox http://www.daringfireball.net/

在Fiddler检查员(原始视图)中,您会看到:

GET https://daringfireball.net/css/ie_sucks HTTP/1.1
Host: daringfireball.net
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/65.0.3325.181 Safari/537.36
Accept: text/css,*/*;q=0.1
Referer: https://daringfireball.net/
Accept-Encoding: gzip, deflate

而在没有--headless的情况下运行相同的命令会给你:

GET https://daringfireball.net/css/ie_sucks.php HTTP/1.1
Host: daringfireball.net
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Accept: text/css,*/*;q=0.1
Referer: https://daringfireball.net/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8

2 个答案:

答案 0 :(得分:1)

在运行无头模式时,将以下内容设置为选项:

'--lang=en-GB'

答案 1 :(得分:0)

看来Accept-Language是仅当浏览器有确认的用户指定语言时发送的用户配置文件标头,并且无头的用户无法发送或不发送该标头。这些帖子在这些帖子中被提出,并且在可预见的未来看起来是一个缺乏的特征:

https://github.com/SeleniumHQ/selenium/issues/4437 https://bugs.chromium.org/p/chromedriver/issues/detail?id=1925

相关问题