Skip to content

Commit 800ce92

Browse files
wolfibDevtools-frontend LUCI CQ
authored andcommitted
Update documentation: use base::Features instead of DevTools experiments
Bug: none Change-Id: I34240f5ad7f29066301ccdfba5d011ccf08a5fd4 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6316797 Reviewed-by: Changhao Han <[email protected]> Auto-Submit: Wolfgang Beyer <[email protected]> Commit-Queue: Changhao Han <[email protected]>
1 parent 4bb0c96 commit 800ce92

File tree

1 file changed

+74
-58
lines changed

1 file changed

+74
-58
lines changed

docs/contributing/settings-experiments-features.md

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,85 @@
11
# Settings, Experiments, and Features in Chromium DevTools
22

33
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+
615

716
[TOC]
817

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+
979
## How to add experiments
1080
81+
Note: Adding new DevTools experiments is deprecated, please use a `base::Feature` instead.
82+
1183
If you want to launch a new feature in DevTools behind an experiment flag, you
1284
will need to do two things:
1385
@@ -81,59 +153,3 @@ if(Root.Runtime.experiments.isEnabled('yourExperimentNameHere')) {
81153
// Experiment code here
82154
}
83155
```
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

Comments
 (0)