运行钴时,我可以从日志中看到用户代理:
[0101/000230:INFO:application.cc(690)] User Agent: Mozilla/5.0 (DirectFB; Linux x86_64) Cobalt/4.13031-qa (unlike Gecko) Starboard/1
那么它是从哪里来的呢?有没有办法改变它?
运行钴时,我可以从日志中看到用户代理:
[0101/000230:INFO:application.cc(690)] User Agent: Mozilla/5.0 (DirectFB; Linux x86_64) Cobalt/4.13031-qa (unlike Gecko) Starboard/1
那么它是从哪里来的呢?有没有办法改变它?
默认用户代理设置在以下文件中,您可以检查一下:
std::string UserAgentStringFactory::CreateUserAgentString() {
// Cobalt's user agent contains the following sections:
// Mozilla/5.0 (ChromiumStylePlatform)
// Cobalt/Version.BuildNumber-BuildConfiguration (unlike Gecko)
// Starboard/APIVersion,
// Device/FirmwareVersion (Brand, Model, ConnectionType)
// Mozilla/5.0 (ChromiumStylePlatform)
std::string user_agent =
base::StringPrintf("Mozilla/5.0 (%s)", CreatePlatformString().c_str());
// Cobalt/Version.BuildNumber-BuildConfiguration (unlike Gecko)
base::StringAppendF(&user_agent, " Cobalt/%s.%s-%s (unlike Gecko)",
COBALT_VERSION, COBALT_BUILD_VERSION_NUMBER,
kBuildConfiguration);
// Starboard/APIVersion,
if (!starboard_version_.empty()) {
base::StringAppendF(&user_agent, " %s", starboard_version_.c_str());
}
// Device/FirmwareVersion (Brand, Model, ConnectionType)
if (youtube_tv_info_) {
base::StringAppendF(
&user_agent, ", %s_%s_%s/%s (%s, %s, %s)",
youtube_tv_info_->network_operator.value_or("").c_str(),
CreateDeviceTypeString().c_str(),
youtube_tv_info_->chipset_model_number.value_or("").c_str(),
youtube_tv_info_->firmware_version.value_or("").c_str(),
youtube_tv_info_->brand.c_str(), youtube_tv_info_->model.c_str(),
CreateConnectionTypeString().c_str());
}
return user_agent;
}
如果你SbSystemGetDeviceType()
是真的SystemDeviceTypeIsTv()
(在文件中user_agent_string_factory_starboard.cc
),你可以通过实现SbSystemGetProperty()
+一些SbSystemGet()
功能的一些字段来自定义UA。
这是一个典型的例子:
Mozilla/5.0 ( 1 ) Cobalt/11.119147-gold (不像 Gecko) Starboard/8, 2 _ 8 _ 6 / 5 ( 3 , 4 , 7 )
在哪里,
- kSbSystemPropertyPlatformName
- kSbSystemPropertyNetworkOperatorName
- kSbSystemPropertyManufacturerName
- kSbSystemPropertyModelName
- kSbSystemPropertyFirmwareVersion
- kSbSystemPropertyChipsetModelNumber
- SbSystemGetConnectionType()
- SbSystemGetDeviceType()