Skip to content

Commit 3a2e387

Browse files
authored
Add ENABLE_NETWORK_THROTTLING experiment (#279)
1 parent dbc1c52 commit 3a2e387

9 files changed

Lines changed: 49 additions & 6 deletions

File tree

front_end/core/rn_experiments/experimentsImpl.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,9 @@ Instance.register({
190190
title: 'Enable performance frames track',
191191
unstable: true,
192192
});
193+
194+
Instance.register({
195+
name: RNExperimentName.ENABLE_NETWORK_THROTTLING,
196+
title: 'Enable network throttling (Network panel)',
197+
unstable: true,
198+
});

front_end/core/root/Runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ export enum RNExperimentName {
306306
REACT_NATIVE_SPECIFIC_UI = 'react-native-specific-ui',
307307
JS_HEAP_PROFILER_ENABLE = 'js-heap-profiler-enable',
308308
ENABLE_TIMELINE_FRAMES = 'enable-timeline-frames',
309+
ENABLE_NETWORK_THROTTLING = 'enable-network-throttling',
309310
}
310311

311312
export enum ConditionName {
@@ -341,6 +342,7 @@ export const enum ExperimentName {
341342
REACT_NATIVE_SPECIFIC_UI = RNExperimentName.REACT_NATIVE_SPECIFIC_UI,
342343
NOT_REACT_NATIVE_SPECIFIC_UI = '!' + RNExperimentName.REACT_NATIVE_SPECIFIC_UI,
343344
ENABLE_TIMELINE_FRAMES = RNExperimentName.ENABLE_TIMELINE_FRAMES,
345+
ENABLE_NETWORK_THROTTLING = RNExperimentName.ENABLE_NETWORK_THROTTLING,
344346
}
345347

346348
export enum GenAiEnterprisePolicyValue {

front_end/entrypoints/rn_fusebox/FuseboxFeatureObserver.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ const UIStrings = {
2929
* @description Title shown when a feature is unavailable due to multiple React Native hosts.
3030
*/
3131
multiHostFeatureUnavailableTitle: 'Feature is unavailable',
32+
/**
33+
* @description Message for the "settings changed" banner shown when a reload
34+
* is required for response throttling in the Network panel.
35+
*/
36+
reloadRequiredForNetworkThrottlingMessage:
37+
'Network throttling is now available in the Network panel. Please reload to enable.',
3238
/**
3339
* @description Message for the "settings changed" banner shown when a reload
3440
* is required for frame timings in the Performance panel.
@@ -81,7 +87,8 @@ export class FuseboxFeatureObserver implements
8187
#handleMetadataUpdated(
8288
event: Common.EventTarget.EventTargetEvent<Protocol.ReactNativeApplication.MetadataUpdatedEvent>): void {
8389
// eslint-disable-next-line @typescript-eslint/naming-convention
84-
const {unstable_isProfilingBuild, unstable_networkInspectionEnabled, unstable_frameRecordingEnabled} = event.data;
90+
const {unstable_isProfilingBuild, unstable_networkInspectionEnabled, unstable_frameRecordingEnabled, unstable_networkThrottlingEnabled} =
91+
event.data;
8592

8693
if (unstable_isProfilingBuild) {
8794
FuseboxWindowTitleManager.instance().setSuffix('[PROFILING]');
@@ -97,6 +104,10 @@ export class FuseboxFeatureObserver implements
97104
if (unstable_frameRecordingEnabled) {
98105
void this.#ensureTimelineFramesEnabled();
99106
}
107+
108+
if (unstable_networkThrottlingEnabled) {
109+
void this.#ensureNetworkThrottlingEnabled();
110+
}
100111
}
101112

102113
#handleSystemStateChanged(
@@ -150,6 +161,14 @@ export class FuseboxFeatureObserver implements
150161
}
151162
}
152163

164+
async #ensureNetworkThrottlingEnabled(): Promise<void> {
165+
if (!Root.Runtime.experiments.isEnabled(Root.Runtime.RNExperimentName.ENABLE_NETWORK_THROTTLING)) {
166+
Root.Runtime.experiments.setEnabled(Root.Runtime.RNExperimentName.ENABLE_NETWORK_THROTTLING, true);
167+
UI.InspectorView?.InspectorView?.instance()?.displayReloadRequiredWarning(
168+
i18nString(UIStrings.reloadRequiredForNetworkThrottlingMessage));
169+
}
170+
}
171+
153172
#disableSingleHostOnlyFeatures(): void {
154173
if (this.#singleHostFeaturesDisabled) {
155174
return;

front_end/generated/InspectorBackendCommands.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front_end/generated/protocol.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ export namespace ReactNativeApplication {
6262
*/
6363
unstable_networkInspectionEnabled?: boolean;
6464
/**
65-
* Whether Frame Timings and screenshots are supported in performance
66-
* traces.
65+
* Whether Frame Timings and screenshots are supported in performance traces.
6766
*/
6867
unstable_frameRecordingEnabled?: boolean;
68+
/**
69+
* Whether network throttling is supported in the Network panel.
70+
*/
71+
unstable_networkThrottlingEnabled?: boolean;
6972
}
7073

7174
/**

front_end/panels/network/NetworkPanel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,10 @@ export class NetworkPanel extends UI.Panel.Panel implements
482482
void UI.ViewManager.ViewManager.instance().showView('network.config');
483483
}, this);
484484
this.panelToolbar.appendToolbarItem(networkConditionsButton);
485+
} else if (Root.Runtime.experiments.isEnabled(Root.Runtime.RNExperimentName.ENABLE_NETWORK_THROTTLING)) {
486+
// [RN] Expose the network throttling selector when enabled by the backend.
487+
this.panelToolbar.appendSeparator();
488+
this.panelToolbar.appendToolbarItem(this.throttlingSelect);
485489
}
486490

487491
this.rightToolbar.appendToolbarItem(new UI.Toolbar.ToolbarItem(this.progressBarContainer));

front_end/testing/EnvironmentHelpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const REGISTERED_EXPERIMENTS = [
131131
Root.Runtime.ExperimentName.REACT_NATIVE_SPECIFIC_UI,
132132
Root.Runtime.ExperimentName.NOT_REACT_NATIVE_SPECIFIC_UI,
133133
Root.Runtime.ExperimentName.ENABLE_TIMELINE_FRAMES,
134+
Root.Runtime.ExperimentName.ENABLE_NETWORK_THROTTLING,
134135
];
135136

136137
export async function initializeGlobalVars({reset = true} = {}) {

third_party/blink/public/devtools_protocol/browser_protocol.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
"description": "Whether Frame Timings and screenshots are supported in performance traces.",
7676
"optional": true,
7777
"type": "boolean"
78+
},
79+
{
80+
"name": "unstable_networkThrottlingEnabled",
81+
"description": "Whether network throttling is supported in the Network panel.",
82+
"optional": true,
83+
"type": "boolean"
7884
}
7985
]
8086
},
@@ -84,7 +90,7 @@
8490
"parameters": [
8591
{
8692
"name": "isSingleHost",
87-
"description": "Whether the application has a single React Native host. If an app or\nframework intantiates multiple hosts, some debugger features will not\n behave safely and should be dynamically disabled.",
93+
"description": "Whether the application has a single React Native host. If an app or\nframework intantiates multiple hosts, some debugger features will not\nbehave safely and should be dynamically disabled.",
8894
"type": "boolean"
8995
}
9096
]
@@ -32044,4 +32050,4 @@
3204432050
]
3204532051
}
3204632052
]
32047-
}
32053+
}

third_party/blink/public/devtools_protocol/react_native_domains.pdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ experimental domain ReactNativeApplication
3232
optional boolean unstable_networkInspectionEnabled
3333
# Whether Frame Timings and screenshots are supported in performance traces.
3434
optional boolean unstable_frameRecordingEnabled
35+
# Whether network throttling is supported in the Network panel.
36+
optional boolean unstable_networkThrottlingEnabled
3537

3638
# Emitted when assertions about the debugger backend have changed.
3739
event systemStateChanged

0 commit comments

Comments
 (0)