Chrome使用-移动用户代理不工作
使用标志--use-mobile-user-agent从命令行运行chrome不会在移动上下文(用户代理)中打开浏览器。
chrome --use-mobile-user-agent= true注:
传递用户代理选项确实有效,但是我觉得这不是正确的方法,因为chrome为您提供了在移动上下文中引导此标志的方法。
--user-agent= Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; ar) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3铬源代码
阅读一些chromium source code,我看到以下内容:
content_switches.cc
从kUseMobileUserAgent标志定义"use-mobile-user-agent":设置铬何时使用移动用户代理。
const char kUseMobileUserAgent[] = "use-mobile-user-agent";shell_content_client.cc
如果变量开关为true/set,则在产品中添加"Mobile“。
std::string GetShellUserAgent() {
std::string product = "Chrome/" CONTENT_SHELL_VERSION;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kUseMobileUserAgent))
product += " Mobile";
return BuildUserAgentFromProduct(product);
}额外的细节(从selenium运行)
作为一个额外的细节,我在使用selenium中运行chrome并传递以下配置:
...
"browserName": "chrome",
"chromeOptions": {
"args": [
"--user-agent= Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; ar) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3",
"--window-size=320,640",
"--disable-popup-blocking",
"--incognito",
"--test-type"
]
},
...发布于 2016-09-27 20:51:00
该字符串构建为GetShellUserAgent中的"Chrome/53.0.2785.116 Mobile“,然后在BuildUserAgentFromProduct中不使用产品,并将其传递给BuildUserAgentFromOSAndProduct,BuildUserAgentFromOSAndProduct应该将字符串设置为这样的格式;
"Mozilla/5.0 (%s) AppleWebKit/%d.%d (KHTML, like Gecko) %s Safari/%d.%d"产品字符串插入令牌4,其中第四个替换令牌位于"Safari“之前。因此,"Chrome/53.0.2785.116移动“应该放在那里。
有和没有标志,我的用户代理是相同的。
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36这是什么意思,它坏了吗?很有可能。
在src/extensions/shell/common/shell_content_client.cc中,BuildUserAgentFromProduct("Chrome/" PRODUCT_VERSION)在ShellContentClient::GetUserAgent中被调用。这只是绕过了对GetShellUserAgent的调用。
井。有移动用户代理标志。还有其他地方可以更换这种产品,但这正是罪魁祸首所在。
https://stackoverflow.com/questions/39559523
复制相似问题