blob: c46e3d7c7e128329255dc0833dc07c3c4db03e96 [file] [log] [blame] [view]
Yashar Dabiran91ea4a872019-02-19 15:46:291# Runtime Enabled Features
2## Overview
3Runtime flags enable Blink developers the ability to control access Chromium users have to new features they implement. Features that are hidden behind a runtime flag are known as Runtime Enabled Features. It is a requirement of the Blink Launch Process to implement new web exposed features behind a runtime flag until an Intent To Ship has been approved.
4
5## Adding A Runtime Enabled Feature
6Runtime Enabled Features are defined in runtime_enabled_features.json5 in alphabetical order. Add your feature's flag to this file and the rest will be generated for you automatically.
7
8Example:
9```js
10{
11 name: "AmazingNewFeature",
12 status: "experimental",
13}
14```
15The status of the feature controls when it will be enabled in the Blink engine.
16
Xianzhu Wangadb0670a22020-07-16 23:04:5817| Status Value | Web feature enabled during [web tests] with content_shell [1] | Web feature enabled as part of web experimental features [2] | Web feature enabled in stable release | Non-web exposed feature enabled through a command line flag [3]
Yashar Dabiran91ea4a872019-02-19 15:46:2918|:---:|:---:|:---:|:---:|:---:|
19| <missing\> | No | No | No | Yes |
20| `test` | Yes | No | No | No |
21| `experimental` | Yes | Yes | No | No |
22| `stable` | Yes | Yes | Yes | No |
23
Xianzhu Wangfeae8952020-07-16 18:07:5724\[1]: content_shell will not enable experimental/test features by default. The `--run-web-tests` flag used as part of running web tests enables this behaviour. The `--enable-blink-test-features` flag also enables this behavior in Chromium and content_shell's browser mode.
Yashar Dabiran91a8662d2019-02-19 18:56:0225
26\[2]: Navigate to about:flags in the URL bar and turn on "Enable experimental web platform features" (formerly, "Enable experimental WebKit features") **or** run Chromium with `--enable-experimental-web-platform-features` (formerly, --enable-experimental-webkit-features).
Yashar Dabiran91ea4a872019-02-19 15:46:2927Works in all Chromium channels: canary, dev, beta, and stable.
Yashar Dabiran91a8662d2019-02-19 18:56:0228
29\[3]: For features that are not web exposed features but require code in Blink to be triggered. Such feature can have a about:flags entry or be toggled based on other signals. Such entries should be called out in a comment to differentiate them from stalled entries.
Yashar Dabiran91ea4a872019-02-19 15:46:2930
31### Platform-specific Feature Status
32For features that do not have the same status on every platform, you can specify their status using a dictionary value.
33
34For example in the declaration below:
35```js
36{
37 name: "NewFeature",
38 status: {
39 "Android": "test",
40 "ChromeOS": "experimental",
41 "Win": "stable",
42 "default": "",
43 }
44}
45```
46the feature has the status `test` on Android, `experimental` on Chrome OS and `stable` on Windows and no status on the other platforms.
47The status of all the not-specified platforms is set using the `default` key. For example, the declaration:
48```js
49status: {
50 "Android": "stable",
51 "default", "experimental",
52}
53```
54will set the feature status to `experimental` on all platforms except on Android (which will be set to `stable`).
55
56**Note:** Omitting `default` from the status dictionary will be treated the same as writing `"default": ""`.
57
58**Note:** You can find the list of all supported platforms in [runtime_enabled_features.json5 status declaration][supportedPlatforms].
59
60### Guidelines for Setting Feature Status
61Any in-development feature can be added with no status, the only requirement is that code OWNERS are willing to have the code landed in the tree (as for any commit).
62
Xianzhu Wangfeae8952020-07-16 18:07:5763* For a feature to be marked `status: "test"`, it must be in a sufficient state to permit internal testing. For example, enabling it should not be known to easily cause crashes, leak memory, or otherwise significantly effect the reliability of bots. Consideration should also be given to the potential for loss of test coverage of shipping behavior. For example, if a feature causes a new code path to be taken instead of an existing one, it is possible that some valuable test coverage and regression protection could be lost by setting a feature to `status: "test"`. Especially, using `status: "test"` for features that have substantially different code paths from the shipped product is strongly discouraged. Consider using a [virtual test suite] or setting up a [flag-specific] [trybot (example)] when it's important to keep testing both old and new code paths. [LayoutNG] and [BlinkGenPropertyTrees] are examples of features where we ensured test coverage of both new and old code paths until they were fully launched, without using `status: "test"`. See the linked document/bug for how we achieved that.
Yashar Dabiran91ea4a872019-02-19 15:46:2964
Xianzhu Wangfeae8952020-07-16 18:07:5765* For a feature to be marked `status: "experimental"`, it should be far enough along to permit testing by early adopter web developers. Many chromium enthusiasts run with `--enable-experimental-web-platform-features`, and so promoting a feature to experimental status can be a good way to get early warning of any stability or compatibility problems. If such problems are discovered (e.g. major websites being seriously broken when the feature is enabled), the feature should be demoted back to no status or `status: "test"` to avoid creating undue problems for such users. It's notoriously difficult to diagnose a bug report from a user who neglects to mention that they have this flag enabled. Often a feature will be set to experimental status long before it's implementation is complete, and while there is still substantial churn on the API design. Features in this state are not expected to work completely, just do something of value which developers may want to provide feedback on.
Yashar Dabiran91ea4a872019-02-19 15:46:2966
Mason Freed02450ef2020-09-03 22:50:5867 **Note:** features set to "experimental" should **not** be expected to cause significant breakage of existing major sites. The primary use case is new APIs or features that are not expected to cause compat issues. If your feature could be reasonably expected to cause compat issues, please keep it marked no status or `status:"test"` [4], and instead use the Finch system, which is better suited to detect and disable such features in case of problems.
68
69\[4]: In this case, "no status" is preferred to `status:"test"` unless you can ensure test coverage of the code paths with the feature disabled. See the `status:"test"` section for more details.
70
Xianzhu Wangfeae8952020-07-16 18:07:5771* For a feature to be marked `status: "stable"`, it must be complete and ready for use by all chrome users. Often this means it has gotten approval via the [blink launch process]. However, for features which are not web observable (e.g. a flag to track a large-scale code refactoring), this approval is not needed. In rare cases a feature may be tested on canary and dev channels by temporarily setting it to `status: "stable"`, with a comment pointing to a bug marked `Release-Block-Beta` tracking setting the feature back to `status: "experimental"` before the branch for beta.
Yashar Dabiran91ea4a872019-02-19 15:46:2972
73When a feature has shipped and is no longer at risk of needing to be disabled, it's associated RuntimeEnableFeatures entry should be removed entirely. Permanent features should generally not have flags.
74
Xianzhu Wangfeae8952020-07-16 18:07:5775If a feature is not stable and no longer under active development, remove `status: "test"/"experimental"` on it (and consider deleting the code implementing the feature).
Yashar Dabiran91ea4a872019-02-19 15:46:2976
Xianzhu Wang05355f4a2020-09-02 01:22:1677### Relationship between a Chromium Feature and a Blink Feature
78
Ali Beyad2846b832021-10-06 03:10:2379In some cases, e.g. for finch experiment, you may need to define a Chromium feature for a blink feature. Their relationship is
Xianzhu Wang05355f4a2020-09-02 01:22:1680defined in [content/child/runtime_features.cc]. See the [initialize blink features] doc for more details.
81
82**Note:** If a feature is implemented at both Chromium side and blink side, as the blink feature doesn't fully work by itself, we normally don't set the blink feature's status so that the Chromium feature can fully control the blink feature ([example][controlled by chromium feature]).
83
Lingqi Chi5de54a32021-10-27 05:03:5984### Introducing dependencies among Runtime Enabled Features
85
86The parameters of `implied_by` and `depends_on` can be used to specify the relationship to other features.
87
88* "implied_by": With this field specified, this feature is enabled automatically if any of the implied_by features is enabled.
89
90* "depends_on": With this field specified, this feature is enabled only if all of the depends_on features are enabled.
91
92**Note:** Only one of `implied_by` and `depends_on` can be specified.
93
Yashar Dabiran91ea4a872019-02-19 15:46:2994### Runtime Enabled CSS Properties
95
96If your feature is adding new CSS Properties you will need to use the runtime_flag argument in [renderer/core/css/css_properties.json5][cssProperties].
97
98## Using A Runtime Enabled Feature
99
100### C++ Source Code
101Add this include:
102```cpp
103#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
104```
105This will provide following static methods to check/set whether your feature is enabled:
106```cpp
107bool RuntimeEnabledFeatures::AmazingNewFeatureEnabled();
108void RuntimeEnabledFeatures::SetAmazingNewFeatureEnabled(bool enabled);
109```
110**Note:** MethodNames and FeatureNames are in UpperCamelCase. This is handled automatically in code generators, and works even if the feature's flag name begins with an acronym such as "CSS", "IME", or "HTML".
111For example "CSSMagicFeature" becomes `RuntimeEnabledFeatures::CSSMagicFeatureEnabled()` and `RuntimeEnabledFeatures::SetCSSMagicFeatureEnabled(bool)`.
112
113
114### IDL Files
115Use the [Blink extended attribute] `[RuntimeEnabled]` as in `[RuntimeEnabled=AmazingNewFeature]` in your IDL definition.
116
117**Note:** FeatureNames are in UpperCamelCase; please use this case in IDL files.
118
119You can guard the entire interface, as in this example:
120```
121[
122 RuntimeEnabled=AmazingNewFeature // Guard the entire interface.
123] interface AmazingNewObject {
124 attribute DOMString amazingNewAttribute;
125 void amazingNewMethod();
126};
127```
128Alternatively, you can guard individual definition members:
129```
130interface ExistingObject {
131 attribute DOMString existingAttribute;
132 // Guarded attribute.
133 [RuntimeEnabled=AmazingNewFeature] attribute DOMString amazingNewAttribute;
134 // Guarded method.
135 [RuntimeEnabled=AmazingNewFeature] void amazingNewMethod();
136};
137```
138**Note:** You *cannot* guard individual arguments, as this is very confusing and error-prone. Instead, use overloading and guard the overloads.
139
140For example, instead of:
141```
142interface ExistingObject {
143 foo(long x, [RuntimeEnabled=FeatureName] optional long y); // Don't do this!
144};
145```
146do:
147```
148interface ExistingObject {
149 // Overload can be replaced with optional if [RuntimeEnabled] is removed
150 foo(long x);
151 [RuntimeEnabled=FeatureName] foo(long x, long y);
152};
153```
154
155**Warning:** You will not be able to change the enabled state of these at runtime as the V8 object templates definitions are created during start up and will not be updated during runtime.
156
157## Web Tests (JavaScript)
Xianzhu Wangadb0670a22020-07-16 23:04:58158
159In [web tests], you can test whether a feature is enabled using:
Yashar Dabiran91ea4a872019-02-19 15:46:29160```javascript
161internals.runtimeFlags.amazingNewFeatureEnabled
162```
Xianzhu Wangadb0670a22020-07-16 23:04:58163This attribute is read only and cannot be changed, unless `settable_from_internals: true` is specified for the feature.
Yashar Dabiran91ea4a872019-02-19 15:46:29164
Xianzhu Wangadb0670a22020-07-16 23:04:58165**Note:** The `internals` JavaScript API is only available in content_shell for use by web tests and does not appear in Chromium. In content_shell's browser mode, `--expose-internals-for-testing` is needed to have the `internals` JavaScript API.
Yashar Dabiran91ea4a872019-02-19 15:46:29166
Francis McCabe83913672021-03-30 18:52:12167**Note:** If your runtime feature is called `AmazingNewFeature`, the Javascript variable name is `internals.runtimeFlags.amazingNewFeatureEnabled`.
168
Yashar Dabiran91ea4a872019-02-19 15:46:29169### Running Web Tests
Xianzhu Wangadb0670a22020-07-16 23:04:58170When content_shell is run for web tests with `--stable-release-mode` flag, test-only and experimental features (ones listed in [runtime_enabled_features.json5] with `status: "test"` or `status: "experimental"`) are turned off. The [virtual/stable] suite runs with the flag, which is one of the ways to ensure test coverage of production code path for these features.
Yashar Dabiran91ea4a872019-02-19 15:46:29171
172## Generated Files
173[renderer/build/scripts/make_runtime_features.py][make_runtime_features.py] uses [runtime_enabled_features.json5] to generate:
174```
175<compilation directory>/gen/third_party/blink/renderer/platform/runtime_enabled_features.h
176<compilation directory>/gen/third_party/blink/renderer/platform/runtime_enabled_features.cc
177```
178[renderer/build/scripts/make_internal_runtime_flags.py][make_internal_runtime_flags.py] uses [runtime_enabled_features.json5] to generate:
179```
180<compilation directory>/gen/third_party/blink/renderer/core/testing/internal_runtime_flags.idl
181<compilation directory>/gen/thrid_party/blink/renderer/core/testing/internal_runtime_flags.h
182```
183[renderer/bindings/scripts/code_generator_v8.py][code_generator_v8.py] uses the generated `internal_runtime_flags.idl` to generate:
184```
185<compilation directory>/gen/third_party/blink/renderer/bindings/core/v8/v8_internal_runtime_flags.h
186<compilation directory>/gen/third_party/blink/renderer/bindings/core/v8/v8_internal_runtime_flags.cc
187```
188## Command-line Switches
189`content` provides two switches which can be used to turn runtime enabled features on or off, intended for use during development. They are exposed by both `content_shell` and `chrome`.
190```
191--enable-blink-features=SomeNewFeature,SomeOtherNewFeature
192--disable-blink-features=SomeOldFeature
193```
194After applying most other feature settings, the features requested feature settings (comma-separated) are changed. "disable" is applied later (and takes precedence), regardless of the order the switches appear on the command line. These switches only affect Blink's state. Some features may need to be switched on in Chromium as well; in this case, a specific flag is required.
195
196**Announcement**
197https://groups.google.com/a/chromium.org/d/msg/blink-dev/JBakhu5J6Qs/re2LkfEslTAJ
198
199
Xianzhu Wangadb0670a22020-07-16 23:04:58200[web tests]: <https://chromium.googlesource.com/chromium/src/+/master/docs/testing/web_tests.md>
Yashar Dabiran91ea4a872019-02-19 15:46:29201[supportedPlatforms]: <https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/platform/runtime_enabled_features.json5#36>
202[cssProperties]: <https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/core/css/css_properties.json5>
203[virtual test suite]: <https://chromium.googlesource.com/chromium/src/+/master/docs/testing/web_tests.md#testing-runtime-flags>
Xianzhu Wangfeae8952020-07-16 18:07:57204[flag-specific]: <https://chromium.googlesource.com/chromium/src/+/master/docs/testing/web_tests.md#testing-runtime-flags>
205[trybot (example)]: <https://chromium-review.googlesource.com/c/chromium/src/+/1850255>
Xianzhu Wange86080d2020-07-16 20:59:14206[LayoutNG]: <https://docs.google.com/document/d/17t6HjA5X8T5xq1LlKoLEGTn_MioGCdEPpijpJeLalK0/edit#heading=h.guvbepjyp0oj>
Xianzhu Wangfeae8952020-07-16 18:07:57207[BlinkGenPropertyTrees]: <https://crbug.com/836884>
Yashar Dabiran91ea4a872019-02-19 15:46:29208[blink launch process]: <https://www.chromium.org/blink/launching-features>
209[Blink extended attribute]: <https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/bindings/IDLExtendedAttributes.md>
210[make_runtime_features.py]: <https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/build/scripts/make_runtime_features.py>
211[runtime_enabled_features.json5]: <https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/platform/runtime_enabled_features.json5>
212[make_internal_runtime_flags.py]: <https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/build/scripts/make_internal_runtime_flags.py>
213[code_generator_v8.py]: <https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/bindings/scripts/code_generator_v8.py>
Xianzhu Wangadb0670a22020-07-16 23:04:58214[virtual/stable]: <https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/web_tests/VirtualTestSuites;drc=9878f26d52d32871ed1c085444196e5453909eec;l=112>
Xianzhu Wang05355f4a2020-09-02 01:22:16215[content/child/runtime_features.cc]: <https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/common/features.cc>
216[initialize blink features]: <https://chromium.googlesource.com/chromium/src/+/master/docs/initialize_blink_features.md>
217[controlled by chromium feature]: <https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/platform/runtime_enabled_features.json5;drc=70bddadf50a14254072cf7ca0bcf83e4331a7d4f;l=833>