Skip to content

Commit e94fcbe

Browse files
authored
Add support for reading network panel metadata from the target (#146)
1 parent d126cc8 commit e94fcbe

11 files changed

Lines changed: 71 additions & 17 deletions

File tree

config/gni/devtools_grd_files.gni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ grd_files_debug_sources = [
891891
"front_end/entrypoints/node_app/NodeMain.js",
892892
"front_end/entrypoints/node_app/nodeConnectionsPanel.css.js",
893893
"front_end/entrypoints/rn_fusebox/FuseboxAppMetadataObserver.js",
894-
"front_end/entrypoints/rn_fusebox/FuseboxProfilingBuildObserver.js",
894+
"front_end/entrypoints/rn_fusebox/FuseboxExperimentsObserver.js",
895895
"front_end/entrypoints/rn_fusebox/FuseboxReconnectDeviceButton.js",
896896
"front_end/entrypoints/rn_fusebox/FuseboxWindowTitleManager.js",
897897
"front_end/entrypoints/shell/browser_compatibility_guard.js",

front_end/core/rn_experiments/experimentsImpl.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,10 @@ Instance.register({
191191
unstable: true,
192192
enabledByDefault: ({ isReactNativeEntryPoint }) => !isReactNativeEntryPoint,
193193
});
194+
195+
Instance.register({
196+
name: RNExperimentName.ENABLE_NETWORK_PANEL,
197+
title: 'Enable Network panel',
198+
unstable: true,
199+
enabledByDefault: () => false,
200+
});

front_end/core/root/Runtime.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export enum RNExperimentName {
280280
REACT_NATIVE_SPECIFIC_UI = 'react-native-specific-ui',
281281
JS_HEAP_PROFILER_ENABLE = 'js-heap-profiler-enable',
282282
ENABLE_PERFORMANCE_PANEL = 'enable-performance-panel',
283+
ENABLE_NETWORK_PANEL = 'enable-network-panel',
283284
}
284285

285286
// TODO(crbug.com/1167717): Make this a const enum again
@@ -320,6 +321,7 @@ export const enum ExperimentName {
320321
JS_HEAP_PROFILER_ENABLE = RNExperimentName.JS_HEAP_PROFILER_ENABLE,
321322
REACT_NATIVE_SPECIFIC_UI = RNExperimentName.REACT_NATIVE_SPECIFIC_UI,
322323
ENABLE_PERFORMANCE_PANEL = RNExperimentName.ENABLE_PERFORMANCE_PANEL,
324+
ENABLE_NETWORK_PANEL = RNExperimentName.ENABLE_NETWORK_PANEL,
323325
}
324326

325327
export interface HostConfigConsoleInsights {
@@ -362,5 +364,7 @@ export type Condition = (config?: HostConfig) => boolean;
362364
export const conditions = {
363365
canDock: () => Boolean(Runtime.queryParam('can_dock')),
364366
notSourcesHideAddFolder: () => Boolean(Runtime.queryParam(ConditionName.NOT_SOURCES_HIDE_ADD_FOLDER)),
365-
reactNativeUnstableNetworkPanel: () => Boolean(Runtime.queryParam(ConditionName.REACT_NATIVE_UNSTABLE_NETWORK_PANEL)),
367+
reactNativeUnstableNetworkPanel: () =>
368+
Boolean(Runtime.queryParam(ConditionName.REACT_NATIVE_UNSTABLE_NETWORK_PANEL)) ||
369+
experiments.isEnabled(ExperimentName.ENABLE_NETWORK_PANEL),
366370
};

front_end/entrypoints/rn_fusebox/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ devtools_module("rn_fusebox") {
1111
sources = [
1212
"FuseboxAppMetadataObserver.ts",
1313
"FuseboxReconnectDeviceButton.ts",
14-
"FuseboxProfilingBuildObserver.ts",
14+
"FuseboxExperimentsObserver.ts",
1515
"FuseboxWindowTitleManager.ts",
1616
]
1717

front_end/entrypoints/rn_fusebox/FuseboxProfilingBuildObserver.ts renamed to front_end/entrypoints/rn_fusebox/FuseboxExperimentsObserver.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,24 @@ import FuseboxWindowTitleManager from './FuseboxWindowTitleManager.js';
1313

1414
const UIStrings = {
1515
/**
16-
* @description Message for the "settings changed" banner shown when a reload is required.
16+
* @description Message for the "settings changed" banner shown when a reload is required for the Performance panel.
1717
*/
18-
reloadRequiredMessage: '[Profiling build first run] One or more settings have changed. Please reload to access the Performance panel.',
18+
reloadRequiredForPerformancePanelMessage:
19+
'[Profiling build first run] One or more settings have changed. Please reload to access the Performance panel.',
20+
/**
21+
* @description Message for the "settings changed" banner shown when a reload is required for the Network panel.
22+
*/
23+
reloadRequiredForNetworkPanelMessage: 'Network panel is now available for dogfooding. Please reload to access it.',
1924
};
2025

21-
const str_ = i18n.i18n.registerUIStrings('entrypoints/rn_fusebox/FuseboxProfilingBuildModeObserver.ts', UIStrings);
26+
const str_ = i18n.i18n.registerUIStrings('entrypoints/rn_fusebox/FuseboxExperimentsObserver.ts', UIStrings);
2227
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
2328

2429
/**
2530
* [Experimental] Model observer which configures available DevTools features
26-
* when a profiling build is identified.
31+
* based on the target's capabilities, e.g. when a profiling build is identified, or when network inspection is supported.
2732
*/
28-
export default class FuseboxProfilingBuildObserver implements
33+
export default class FuseboxFeatureObserver implements
2934
SDK.TargetManager.SDKModelObserver<SDK.ReactNativeApplicationModel.ReactNativeApplicationModel> {
3035
constructor(targetManager: SDK.TargetManager.TargetManager) {
3136
targetManager.observeModels(SDK.ReactNativeApplicationModel.ReactNativeApplicationModel, this);
@@ -43,16 +48,20 @@ export default class FuseboxProfilingBuildObserver implements
4348

4449
#handleMetadataUpdated(
4550
event: Common.EventTarget.EventTargetEvent<Protocol.ReactNativeApplication.MetadataUpdatedEvent>): void {
46-
const {unstable_isProfilingBuild} = event.data;
51+
const {unstable_isProfilingBuild, unstable_networkInspectionEnabled} = event.data;
4752

4853
if (unstable_isProfilingBuild) {
4954
FuseboxWindowTitleManager.instance().setSuffix('[PROFILING]');
50-
this.#hideUnsupportedFeatures();
55+
this.#hideUnsupportedFeaturesForProfilingBuilds();
5156
this.#ensurePerformancePanelEnabled();
5257
}
58+
59+
if (unstable_networkInspectionEnabled) {
60+
this.#ensureNetworkPanelEnabled();
61+
}
5362
}
5463

55-
#hideUnsupportedFeatures(): void {
64+
#hideUnsupportedFeaturesForProfilingBuilds(): void {
5665
UI.ViewManager.ViewManager.instance()
5766
.resolveLocation(UI.ViewManager.ViewLocationValues.PANEL)
5867
.then(location => {
@@ -83,9 +92,24 @@ export default class FuseboxProfilingBuildObserver implements
8392
const inspectorView = UI.InspectorView?.InspectorView?.instance();
8493
if (inspectorView) {
8594
inspectorView.displayReloadRequiredWarning(
86-
i18nString(UIStrings.reloadRequiredMessage),
95+
i18nString(UIStrings.reloadRequiredForPerformancePanelMessage),
8796
);
8897
}
8998
}
9099
}
100+
101+
#ensureNetworkPanelEnabled(): void {
102+
if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.ENABLE_NETWORK_PANEL)) {
103+
return;
104+
}
105+
106+
Root.Runtime.experiments.setEnabled(
107+
Root.Runtime.ExperimentName.ENABLE_NETWORK_PANEL,
108+
true,
109+
);
110+
111+
UI.InspectorView?.InspectorView?.instance()?.displayReloadRequiredWarning(
112+
i18nString(UIStrings.reloadRequiredForNetworkPanelMessage),
113+
);
114+
}
91115
}

front_end/entrypoints/rn_fusebox/rn_fusebox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import * as UI from '../../ui/legacy/legacy.js';
2525
import * as Main from '../main/main.js';
2626
import FuseboxAppMetadataObserver from './FuseboxAppMetadataObserver.js';
2727
import FuseboxReconnectDeviceButton from './FuseboxReconnectDeviceButton.js';
28-
import FuseboxProfilingBuildObserver from './FuseboxProfilingBuildObserver.js';
28+
import FuseboxExperimentsObserver from './FuseboxExperimentsObserver.js';
2929

3030
import type * as Platform from '../../core/platform/platform.js';
3131
import type * as Sources from '../../panels/sources/sources.js';
@@ -164,6 +164,6 @@ UI.Toolbar.registerToolbarItem({
164164
});
165165

166166
new FuseboxAppMetadataObserver(SDK.TargetManager.TargetManager.instance());
167-
new FuseboxProfilingBuildObserver(SDK.TargetManager.TargetManager.instance());
167+
new FuseboxExperimentsObserver(SDK.TargetManager.TargetManager.instance());
168168

169169
Host.rnPerfMetrics.entryPointLoadingFinished('rn_fusebox');

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export namespace ReactNativeApplication {
5757
* Whether the app is a profiling build.
5858
*/
5959
unstable_isProfilingBuild?: boolean;
60+
/**
61+
* Enables the Network Panel.
62+
*/
63+
unstable_networkInspectionEnabled?: boolean;
6064
}
6165
}
6266

front_end/panels/network/network-meta.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const UIStrings = {
2323
*@description Title of the Network tool
2424
*/
2525
network: 'Network',
26+
/**
27+
*@description Title of the Network tool (Expo, unstable)
28+
*/
29+
networkExpoUnstable: 'Network (Expo, unstable)',
2630
/**
2731
*@description Command for showing the 'Network request blocking' tool
2832
*/
@@ -126,6 +130,7 @@ const UIStrings = {
126130
};
127131
const str_ = i18n.i18n.registerUIStrings('panels/network/network-meta.ts', UIStrings);
128132
const i18nLazyString = i18n.i18n.getLazilyComputedLocalizedString.bind(undefined, str_);
133+
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
129134
let loadedNetworkModule: (typeof Network|undefined);
130135

131136
async function loadNetworkModule(): Promise<typeof Network> {
@@ -146,7 +151,9 @@ UI.ViewManager.registerViewExtension({
146151
location: UI.ViewManager.ViewLocationValues.PANEL,
147152
id: 'network',
148153
commandPrompt: i18nLazyString(UIStrings.showNetwork),
149-
title: i18nLazyString(UIStrings.network),
154+
title: () => Root.Runtime.experiments.isEnabled(Root.Runtime.RNExperimentName.ENABLE_NETWORK_PANEL) ?
155+
i18nString(UIStrings.network) :
156+
i18nString(UIStrings.networkExpoUnstable),
150157
order: 40,
151158
condition: Root.Runtime.conditions.reactNativeUnstableNetworkPanel,
152159
async loadView() {

third_party/blink/public/devtools_protocol/browser_protocol.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
"description": "Whether the app is a profiling build.",
6464
"optional": true,
6565
"type": "boolean"
66+
},
67+
{
68+
"name": "unstable_networkInspectionEnabled",
69+
"description": "Enables the Network Panel.",
70+
"optional": true,
71+
"type": "boolean"
6672
}
6773
]
6874
}
@@ -30427,4 +30433,4 @@
3042730433
]
3042830434
}
3042930435
]
30430-
}
30436+
}

0 commit comments

Comments
 (0)