Chrome use-mobile-user-agent not working
Chrome use-mobile-user-agent not working
Chrome use-mobile-user-agent不工作
在带有--use-mobile-user-agent
标志的命令行中运行chrome不能在移动环境(user-agent)中打开浏览器。
chrome --use-mobile-user-agent= true
注意:
传递user-agent选项确实有效,但是我觉得这不是正确的方法,因为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源代码
阅读一些chromium源代码,我看到以下内容:
content_switches.cc
define kUseMobileUserAgent
from "use-mobile-user-agent"
flag:设置Chromium何时应该使用移动用户代理。
const char kUseMobileUserAgent[] = "use-mobile-user-agent";
shell_content_client.cc
如果我们的变量开关为true/set,则添加"Mobile"到product。
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运行)
作为一个额外的细节,我运行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"
]
},
...
字符串在GetShellUserAgent
中构建为"Chrome/53.0.2785.116 Mobile",然后在BuildUserAgentFromProduct
中,不使用product,并传递给BuildUserAgentFromOSAndProduct
,这应该是格式化字符串;
"Mozilla/5.0 (%s) AppleWebKit/%d.%d (KHTML, like Gecko) %s Safari/%d.%d"
将产品字符串插入令牌4,其中第四个替换令牌在"Safari"之前。因此"Chrome/53.0.2785.116 Mobile"应该放在那里。
有和没有标志,我的用户代理是一样的。
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
的调用。
。移动用户代理标志消失了。还有其他地方可以更换产品,但这是最突出的罪魁祸首。
- GDB - strcmp not working: __strcmp_sse2_unaligned
- QT qScriptConnect is not working
- QDesktopServices::openUrl() not working Qt
- "Configure: Error: Could Not Find a Working Compiler, See config.log For Details"
- C++ std::set ordering not working with customer class*
- C++ SetWindowText not working
- visual studio 2012 c++ hello world - iostream not working
- getGravity not working?
- Opencv findcontours CV_RETR_EXTERNAL not working
- c++ srand() not working
- std::queue::empty() not working?
- BCB swprintf not working
- 将类型作为指向另一个类的对象的指针的泛型类-NOT WORKING
- LoadLibrary is not working
- gluUnProject not working
- C++ catch bad_alloc not working
- updatelayeredwindow not working
- OpenMP set_num_threads() is not working
- glOrtho not working
- Cuda atomicInc not working