0

运行钴时,我可以从日志中看到用户代理:

[0101/000230:INFO:application.cc(690)] User Agent: Mozilla/5.0 (DirectFB; Linux x86_64) Cobalt/4.13031-qa (unlike Gecko) Starboard/1

那么它是从哪里来的呢?有没有办法改变它?

4

2 回答 2

1

默认用户代理设置在以下文件中,您可以检查一下:

https://cobalt.googlesource.com/cobalt/+/e9b4b99dab6e774b8b6e63add74c352cc5dd395a/src/cobalt/network/user_agent_string_factory.cc

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;
}
于 2017-02-10T01:11:49.253 回答
0

如果你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 )

在哪里,

  1. kSbSystemPropertyPlatformName
  2. kSbSystemPropertyNetworkOperatorName
  3. kSbSystemPropertyManufacturerName
  4. kSbSystemPropertyModelName
  5. kSbSystemPropertyFirmwareVersion
  6. kSbSystemPropertyChipsetModelNumber
  7. SbSystemGetConnectionType()
  8. SbSystemGetDeviceType()
于 2017-12-08T20:07:08.057 回答