Chrome flags are experimental features that Google developers use for testing new functionality within the Chrome browser and Chromium-based browsers. These flags, accessible via the chrome://flags
URL, offer a way to customize your browsing experience and peek into upcoming features.
However, understanding how these flags work, especially the "Default" settings, can be confusing. This article dives deep into how default values are determined and how you can influence them in your Chromium builds.
The "Default" value you see next to a flag in chrome://flags isn't always straightforward. Here's a breakdown of the factors that influence it:
Peter Kasting, a Chromium developer, explains it succinctly:
"Default" has a default value set by source code but in many cases can be overridden dynamically by the field trial code. Selecting one of the other values forces that value and prevents field trials from toggling it.
This dynamic overriding means that the "Default" value you observe can change based on the field trials your build is participating in.
One common question is why flags have different default values in developer builds compared to official Chrome builds. Several factors contribute to this:
fieldtrial_testing_like_official_build
setting: The common.gypi
file contains a setting called fieldtrial_testing_like_official_build
. When set to 1, it should disable the activation of field trial tests specified in configuration files. However, this setting is ignored if branding=="Chrome"
.VariationsService
to fetch field trial configs from the server, influencing default flag settings.In essence, official builds are designed to participate in field trials, while developer builds may not be configured to do so by default, leading to discrepancies in flag defaults.
The original poster in the discussion sought to make their developer build behave identically to an official build concerning flag defaults. The conclusion reached was:
a developer build cannot behave same as a official one unless fetching field trial configs.
This highlights a key challenge: replicating the exact conditions of an official Chrome build, with all its field trial configurations, in a developer environment is difficult.
While perfectly mirroring official builds might not be feasible, you can still influence flag defaults in your Chromium build. Here's how:
chrome/browser/about_flags.cc
.chrome://flags
.CommandLine::HasSwitch(switches::[flag name])
in the code. You can then modify the code to change the default behavior when the switch is not explicitly specified.content_features.cc
. You might need to override the relevant feature to change the default behavior.Example Scenario:
Let's say you want to change the default value of the kDisableGestureRequirementForMediaPlayback
flag. This flag relates to whether a user gesture is required to play media. Here's a possible approach:
switches::kDisableGestureRequirementForMediaPlayback
.HasSwitch
Calls: Search the Chromium source code for instances where CommandLine::HasSwitch(switches::kDisableGestureRequirementForMediaPlayback)
is called.kCrossOriginMediaPlaybackRequiresUserGesture
feature in content_features.cc
. You might need to override this feature to achieve the desired default behavior.Understanding how Chrome flags and field trials interact is crucial for developers working with Chromium. While perfectly replicating official build behavior in a development environment can be challenging, you can still modify flag defaults by understanding the underlying code, command-line switches, and feature overrides. By carefully examining the Chromium source code, you can gain the control you need to customize your builds and test specific configurations.