diff --git a/docs/api/command-line-switches.md b/docs/api/command-line-switches.md index fe8e7c75aebf..be9cac42b60d 100644 --- a/docs/api/command-line-switches.md +++ b/docs/api/command-line-switches.md @@ -75,6 +75,12 @@ This switch can not be used in `app.commandLine.appendSwitch` since it is parsed earlier than user's app is loaded, but you can set the `ELECTRON_ENABLE_LOGGING` environment variable to achieve the same effect. +## --force-fieldtrials=`trials` + +Field trials to be forcefully enabled or disabled. + +For example: `WebRTC-Audio-Red-For-Opus/Enabled/` + ### --host-rules=`rules` A comma-separated list of `rules` that control how hostnames are mapped. diff --git a/shell/browser/electron_browser_main_parts.cc b/shell/browser/electron_browser_main_parts.cc index e4ae699c6047..8e21a1e5ee65 100644 --- a/shell/browser/electron_browser_main_parts.cc +++ b/shell/browser/electron_browser_main_parts.cc @@ -279,6 +279,9 @@ void ElectronBrowserMainParts::PostEarlyInitialization() { base::FeatureList::ClearInstanceForTesting(); InitializeFeatureList(); + // Initialize field trials. + InitializeFieldTrials(); + // Initialize after user script environment creation. fake_browser_process_->PostEarlyInitialization(); } diff --git a/shell/browser/feature_list.cc b/shell/browser/feature_list.cc index 9e1fbb5213ad..59bdd50f6f97 100644 --- a/shell/browser/feature_list.cc +++ b/shell/browser/feature_list.cc @@ -9,6 +9,7 @@ #include "base/base_switches.h" #include "base/command_line.h" #include "base/feature_list.h" +#include "base/metrics/field_trial.h" #include "content/public/common/content_features.h" #include "electron/buildflags/buildflags.h" #include "media/base/media_switches.h" @@ -49,4 +50,12 @@ void InitializeFeatureList() { base::FeatureList::InitializeInstance(enable_features, disable_features); } +void InitializeFieldTrials() { + auto* cmd_line = base::CommandLine::ForCurrentProcess(); + auto force_fieldtrials = + cmd_line->GetSwitchValueASCII(::switches::kForceFieldTrials); + + base::FieldTrialList::CreateTrialsFromString(force_fieldtrials); +} + } // namespace electron diff --git a/shell/browser/feature_list.h b/shell/browser/feature_list.h index 9048c6913d4f..3464bba213c5 100644 --- a/shell/browser/feature_list.h +++ b/shell/browser/feature_list.h @@ -7,6 +7,7 @@ namespace electron { void InitializeFeatureList(); -} +void InitializeFieldTrials(); +} // namespace electron #endif // SHELL_BROWSER_FEATURE_LIST_H_