|
1 | 1 | # Settings, Experiments, and Features in Chromium DevTools |
2 | 2 |
|
3 | 3 | From a developers perspective the Chromium DevTools experience can be |
4 | | -customized in three ways: via Settings\>Preferences, Settings\>Experiments, |
5 | | -or by passing a command line flag to Chromium. |
| 4 | +customized in multiple ways: |
| 5 | + |
| 6 | +* via Settings \> Preferences, |
| 7 | +* via Settings \> Experiments, |
| 8 | +* via `chrome://flags`, |
| 9 | +* or by passing a command line flag to Chromium. |
| 10 | + |
| 11 | +Adding new DevTools experiments is deprecated, the preferred way for adding new |
| 12 | +features / exposing experimental features is via `base::Feature`s. These are |
| 13 | +controllable via Chromium command line parameters or optionally via `chrome://flags`. |
| 14 | + |
6 | 15 |
|
7 | 16 | [TOC] |
8 | 17 |
|
| 18 | +## How to add `base::Feature` feature flags |
| 19 | + |
| 20 | +[go/chrome-devtools:command-line-config](http://go/chrome-devtools:command-line-config) |
| 21 | + |
| 22 | +`base::Feature`s are defined in the Chromium repository and made available to |
| 23 | +DevTools via host bindings. This allows configuring features which have both a |
| 24 | +DevTools front-end and a Chromium back-end component from a single source of |
| 25 | +truth. But front-end-only features can be controlled via a `base::Feature` just |
| 26 | +as well. |
| 27 | + |
| 28 | +By default, `base::Feature`s are configurable via command line parameters when |
| 29 | +launching Chromium. Optionally, they can be made available via the `chrome://flags` |
| 30 | +UI as well. |
| 31 | + |
| 32 | +### Define a new `base::Feature` |
| 33 | + |
| 34 | +Add a new `base::Feature` to DevTools' [`features.cc`](https://crsrc.org/c/chrome/browser/devtools/features.cc). This feature will automatically be available as a Chrome command line parameter: |
| 35 | + |
| 36 | +```cxx |
| 37 | +// in browser_features.cc |
| 38 | + |
| 39 | +BASE_FEATURE(kDevToolsNewFeature, "DevToolsNewFeature", |
| 40 | + base::FEATURE_DISABLED_BY_DEFAULT); |
| 41 | + |
| 42 | +// Optionally add feature parameters |
| 43 | +const base::FeatureParam<std::string> kDevToolsNewFeatureStringParam{ |
| 44 | + &kDevToolsNewFeature, "string_param", /*default_value=*/""}; |
| 45 | +const base::FeatureParam<double> kDevToolsNewFeatureDoubleParam{ |
| 46 | + &kDevToolsNewFeature, "double_param", /*default_value=*/0}; |
| 47 | + |
| 48 | +``` |
| 49 | +
|
| 50 | +Start Chrome via command line including flags: |
| 51 | +
|
| 52 | +``` |
| 53 | +out/Default/chrome --enable-features=DevToolsNewFeature |
| 54 | +``` |
| 55 | +
|
| 56 | +You can even pass additional feature parameters: |
| 57 | +
|
| 58 | +``` |
| 59 | +out/Default/chrome --enable-features="DevToolsNewFeature:string_param/foo/double_param/0.5" |
| 60 | +``` |
| 61 | +
|
| 62 | +### Make the `base::Feature` available via `chrome://flags` |
| 63 | +
|
| 64 | +This step is optional. If you want the `base::Feature` to be controllable via the `chrome://flags` UI and not only via the command line, follow [this documentation](https://chromium.googlesource.com/chromium/src/+/main/docs/how_to_add_your_feature_flag.md#step-2_adding-the-feature-flag-to-the-chrome_flags-ui). |
| 65 | +
|
| 66 | +### Add the new feature to the host configuration being sent to DevTools |
| 67 | +
|
| 68 | + Add the new feature to `DevToolsUIBindings::GetHostConfig` ([link to code](https://crsrc.org/c/chrome/browser/devtools/devtools_ui_bindings.cc;l=1506;drc=dd0b2a0bee86088ec0d481bd8722c06edaaba4a4), [example CL](https://crrev.com/c/5625935)). |
| 69 | +
|
| 70 | +### In DevTools, use the new property added to HostConfig |
| 71 | +
|
| 72 | +* Update the type definition in [`Runtime.ts`](https://crsrc.org/c/third_party/devtools-frontend/src/front_end/core/root/Runtime.ts). |
| 73 | +* Update the dummy value returned by `getHostConfig` in [`InspectorFrontendHost.ts`](https://crsrc.org/c/third_party/devtools-frontend/src/front_end/core/host/InspectorFrontendHost.ts). |
| 74 | +* Access the host config via `Root.Runtime.hostConfig`. |
| 75 | +* In unit tests, make sure to assign the expected configuration using `updateHostConfig({ foo: bar })`. |
| 76 | +
|
| 77 | +Please refer to this [example CL](https://crrev.com/c/5626314). |
| 78 | +
|
9 | 79 | ## How to add experiments |
10 | 80 |
|
| 81 | +Note: Adding new DevTools experiments is deprecated, please use a `base::Feature` instead. |
| 82 | +
|
11 | 83 | If you want to launch a new feature in DevTools behind an experiment flag, you |
12 | 84 | will need to do two things: |
13 | 85 |
|
@@ -81,59 +153,3 @@ if(Root.Runtime.experiments.isEnabled('yourExperimentNameHere')) { |
81 | 153 | // Experiment code here |
82 | 154 | } |
83 | 155 | ``` |
84 | | - |
85 | | -## How to add command line flags |
86 | | - |
87 | | -[go/chrome-devtools:command-line-config](http://go/chrome-devtools:command-line-config) |
88 | | - |
89 | | -In some situations it would be convenient (or is even necessary) to configure |
90 | | -DevTools directly via the command line interface (CLI). This is particularly |
91 | | -useful for features which have both a DevTools front-end and a Chromium back-end |
92 | | -component, and allows configuration from a single source of truth. For live |
93 | | -demos of features which are still under development, this can be very helpful |
94 | | -as well. Presenters would have peace of mind, knowing that their feature is |
95 | | -working correctly, as long as they are re-using the right command to launch |
96 | | -Chromium. |
97 | | - |
98 | | -### Define a new `base::Feature` |
99 | | - |
100 | | -Add a new `base::Feature` to DevTools' [`features.cc`](https://crsrc.org/c/chrome/browser/devtools/features.cc). This feature will automatically be available as a Chrome command line parameter: |
101 | | - |
102 | | -```cxx |
103 | | -// in browser_features.cc |
104 | | - |
105 | | -BASE_FEATURE(kDevToolsNewFeature, "DevToolsNewFeature", |
106 | | - base::FEATURE_DISABLED_BY_DEFAULT); |
107 | | - |
108 | | -// Optionally add feature parameters |
109 | | -const base::FeatureParam<std::string> kDevToolsNewFeatureStringParam{ |
110 | | - &kDevToolsNewFeature, "string_param", /*default_value=*/""}; |
111 | | -const base::FeatureParam<double> kDevToolsNewFeatureDoubleParam{ |
112 | | - &kDevToolsNewFeature, "double_param", /*default_value=*/0}; |
113 | | - |
114 | | -``` |
115 | | -
|
116 | | -Start Chrome via command line including flags: |
117 | | -
|
118 | | -``` |
119 | | -out/Default/chrome --enable-features=DevToolsNewFeature |
120 | | -``` |
121 | | -
|
122 | | -You can even pass additional feature parameters: |
123 | | -
|
124 | | -``` |
125 | | -out/Default/chrome --enable-features="DevToolsNewFeature:string_param/foo/double_param/0.5" |
126 | | -``` |
127 | | -
|
128 | | -### Add the new feature to the host configuration being sent to DevTools |
129 | | -
|
130 | | - Add the new feature to `DevToolsUIBindings::GetHostConfig` ([link to code](https://crsrc.org/c/chrome/browser/devtools/devtools_ui_bindings.cc;l=1506;drc=dd0b2a0bee86088ec0d481bd8722c06edaaba4a4), [example CL](https://crrev.com/c/5625935)). |
131 | | -
|
132 | | -### In DevTools, use the new property added to HostConfig |
133 | | -
|
134 | | -* Update the type definition in [`Runtime.ts`](https://crsrc.org/c/third_party/devtools-frontend/src/front_end/core/root/Runtime.ts). |
135 | | -* Update the dummy value returned by `getHostConfig` in [`InspectorFrontendHost.ts`](https://crsrc.org/c/third_party/devtools-frontend/src/front_end/core/host/InspectorFrontendHost.ts). |
136 | | -* Access the host config via `Root.Runtime.hostConfig`. |
137 | | -* In unit tests, make sure to assign the expected configuration using `updateHostConfig({ foo: bar })`. |
138 | | -
|
139 | | -Please refer to this [example CL](https://crrev.com/c/5626314). |
|
0 commit comments