Search code examples
cobalt

Where did the default Useragent of Cobalt come from?


When run the cobalt, I can see the useragent from the log:

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

So where does it come from? Is there a way to change it?


Solution

  • The default useragent is set in the following file, you can have a check:

    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;
    }