Skip to content

Commit 05a3c7e

Browse files
authored
feat: network inspector - add launch configuration for new inspector (#1798)
### Description This PR introduces additional Launch Configuration option `Use Native Network Inspector Implementation`, which controls whether the new network inspector is enabled. The option can be explicitly set to `Yes` or `No` with caveat, that for react native version < 0.83.0 the inspector will not showcase any massages, which is provided in the description of option. When set to `Detect Automatically` the extension will detect whether current version is >= 0.83.0 and set the flag accordingly. <img width="583" height="682" alt="Screenshot 2025-12-08 at 15 08 20" src="https://github.com/user-attachments/assets/8504d899-e95b-4872-98c5-7dd65cd062a0" /> ### How Has This Been Tested: Changed configuration and used debugger to determine which inspector instance is initialised in `network-plugin.ts` in the constructor, changed the `package.json` of react native module in `node_modules` to `0.83.0` to check whether automatic detection works correctly, verified that changing the option properly edits `launch.json` ### How Has This Change Been Documented: Will have to be done asap, wip for now.
1 parent eec7e00 commit 05a3c7e

File tree

6 files changed

+65
-22
lines changed

6 files changed

+65
-22
lines changed

packages/vscode-extension/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@
884884
"disableNativeBuildStaleChecks": {
885885
"type": "boolean",
886886
"description": "When set to true, Radon will not run fingerprint checks on reloads and after file changes that would detect whether the native code needs to be rebuilt."
887+
},
888+
"useNativeNetworkInspector": {
889+
"type": "boolean",
890+
"description": "When set to true, Radon will use the Native (\"Fusebox\") Network Inspector implementation introduced in 0.83.0. Note that this is only supported on React Native 0.83.0 and newer, and might not intercept network messages on earlier versions."
887891
}
888892
}
889893
}

packages/vscode-extension/src/common/LaunchConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface LaunchOptions {
3333
useCustomJSDebugger?: boolean;
3434
metroPort?: number;
3535
disableNativeBuildStaleChecks?: boolean;
36+
useNativeNetworkInspector?: boolean;
3637
}
3738

3839
export const LAUNCH_OPTIONS_KEYS = [
@@ -50,6 +51,7 @@ export const LAUNCH_OPTIONS_KEYS = [
5051
"preview",
5152
"usePrebuild",
5253
"useOldDevtools",
54+
"useNativeNetworkInspector",
5355
"useCustomJSDebugger",
5456
"metroPort",
5557
"disableNativeBuildStaleChecks",

packages/vscode-extension/src/plugins/network/network-plugin.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
import { commands, Disposable, window } from "vscode";
2-
import { SemVer } from "semver";
32
import { RadonInspectorBridge } from "../../project/inspectorBridge";
43
import { NetworkBridge } from "../../project/networkBridge";
54
import { ToolKey, ToolPlugin } from "../../project/tools";
65
import { extensionContext } from "../../utilities/extensionContext";
76
import { Logger } from "../../Logger";
87
import { NetworkDevtoolsWebviewProvider } from "./NetworkDevtoolsWebviewProvider";
98
import { WebviewMessage } from "../../network/types/panelMessageProtocol";
10-
119
import InspectorBridgeNetworkInspector from "./strategies/InspectorBridgeNetworkInspector";
1210
import DebuggerNetworkInspector from "./strategies/DebuggerNetworkInspector";
1311

1412
export const NETWORK_PLUGIN_ID = "network";
1513

16-
/**
17-
* Minimum React Native minor version that includes debugger network inspector support
18-
*/
19-
const MINIMUM_RN_DEBUGGER_INSPECTOR_VERSION = 83;
20-
2114
export type BroadcastListener = (message: WebviewMessage) => void;
2215

2316
export interface NetworkInspector {
@@ -61,9 +54,9 @@ export class NetworkPlugin implements ToolPlugin {
6154
inspectorBridge: RadonInspectorBridge,
6255
networkBridge: NetworkBridge,
6356
metroPort: number,
64-
reactNativeVersion: SemVer | null
57+
useNativeNetworkInspectorFlag: boolean
6558
) {
66-
this.networkInspector = this.checkDebuggerNetworkInspectorSupport(reactNativeVersion)
59+
this.networkInspector = useNativeNetworkInspectorFlag
6760
? new DebuggerNetworkInspector(inspectorBridge, networkBridge, metroPort)
6861
: new InspectorBridgeNetworkInspector(inspectorBridge, metroPort);
6962
initialize();
@@ -73,14 +66,6 @@ export class NetworkPlugin implements ToolPlugin {
7366
return this.networkInspector.pluginAvailable;
7467
}
7568

76-
private checkDebuggerNetworkInspectorSupport(reactNativeVersion: SemVer | null): boolean {
77-
// using SemVer.compare does not work because it evaluates 0 to false in its implementation
78-
if (!reactNativeVersion || reactNativeVersion.minor < MINIMUM_RN_DEBUGGER_INSPECTOR_VERSION) {
79-
return false;
80-
}
81-
return true;
82-
}
83-
8469
public enable(): void {
8570
this.networkInspector.enable();
8671
}

packages/vscode-extension/src/project/ApplicationContext.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ function checkFuseboxSupport(appRoot: string): boolean {
6161
return supportsFusebox;
6262
}
6363

64+
function checkNativeNetworkInspectorSupport(appRoot: string): boolean {
65+
const reactNativeVersion = getReactNativeVersion(appRoot);
66+
if (reactNativeVersion === null) {
67+
return false;
68+
}
69+
const supportsNativeNetworkInspector = reactNativeVersion.compare("0.83.0") >= 0;
70+
return supportsNativeNetworkInspector;
71+
}
72+
6473
function resolveLaunchConfig(configuration: LaunchConfiguration): ResolvedLaunchConfig {
6574
const appRoot = configuration.appRoot;
6675
const absoluteAppRoot = path.resolve(workspace.workspaceFolders![0].uri.fsPath, appRoot);
@@ -106,6 +115,9 @@ function resolveLaunchConfig(configuration: LaunchConfiguration): ResolvedLaunch
106115
},
107116
usePrebuild: configuration.usePrebuild,
108117
useOldDevtools: configuration.useOldDevtools ?? !checkFuseboxSupport(absoluteAppRoot),
118+
useNativeNetworkInspector:
119+
configuration.useNativeNetworkInspector ??
120+
checkNativeNetworkInspectorSupport(absoluteAppRoot),
109121
};
110122
}
111123

packages/vscode-extension/src/project/tools.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Disposable } from "vscode";
22
import _ from "lodash";
3-
import { SemVer } from "semver";
43
import { RadonInspectorBridge } from "./inspectorBridge";
54
import { NetworkBridge } from "./networkBridge";
65
import { extensionContext } from "../utilities/extensionContext";
@@ -28,7 +27,7 @@ import {
2827
APOLLO_PLUGIN_ID,
2928
ApolloClientDevtoolsPlugin,
3029
} from "../plugins/apollo-client-devtools-plugin/apollo-client-devtools-plugin";
31-
import { ApplicationContext } from "./ApplicationContext";
30+
import { ApplicationContext, ResolvedLaunchConfig } from "./ApplicationContext";
3231

3332
const TOOLS_SETTINGS_KEY = "tools_settings";
3433

@@ -69,7 +68,8 @@ export class ToolsManager implements Disposable {
6968
private activePlugins: Set<ToolPlugin> = new Set();
7069
private disposables: Disposable[] = [];
7170
private readonly workspaceConfigState: StateManager<WorkspaceConfiguration>;
72-
private readonly reactNativeVersion: SemVer | null;
71+
private readonly launchConfig: ResolvedLaunchConfig;
72+
private readonly useNativeNetworkInspectorFlag: boolean;
7373

7474
public constructor(
7575
private readonly stateManager: StateManager<ToolsState>,
@@ -79,7 +79,8 @@ export class ToolsManager implements Disposable {
7979
public readonly metroPort: number
8080
) {
8181
this.workspaceConfigState = this.applicationContext.workspaceConfigState;
82-
this.reactNativeVersion = this.applicationContext.reactNativeVersion;
82+
this.launchConfig = this.applicationContext.launchConfig;
83+
this.useNativeNetworkInspectorFlag = this.launchConfig.useNativeNetworkInspector ?? false;
8384

8485
this.toolsSettings = Object.assign({}, extensionContext.workspaceState.get(TOOLS_SETTINGS_KEY));
8586
for (const plugin of createExpoDevPluginTools()) {
@@ -105,7 +106,12 @@ export class ToolsManager implements Disposable {
105106
this.plugins.set(APOLLO_PLUGIN_ID, new ApolloClientDevtoolsPlugin(inspectorBridge));
106107
this.plugins.set(
107108
NETWORK_PLUGIN_ID,
108-
new NetworkPlugin(inspectorBridge, networkBridge, metroPort, this.reactNativeVersion)
109+
new NetworkPlugin(
110+
inspectorBridge,
111+
networkBridge,
112+
metroPort,
113+
this.useNativeNetworkInspectorFlag
114+
)
109115
);
110116
this.plugins.set(
111117
RENDER_OUTLINES_PLUGIN_ID,

packages/vscode-extension/src/webview/views/LaunchConfigurationView.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function serializeLaunchConfig(formData: FormData, defaultAppRoot: string) {
8989
isExpo: valueAsBoolean(data.isExpo),
9090
env: data.env ? JSON.parse(data.env) : {},
9191
usePrebuild: valueAsBoolean(data.usePrebuild),
92+
useNativeNetworkInspector: valueAsBoolean(data.useNativeNetworkInspector),
9293
};
9394

9495
for (const platform of ["ios", "android"] as const) {
@@ -300,6 +301,39 @@ function LaunchConfigurationView({
300301
</SingleSelect>
301302
</FormGroup>
302303

304+
<FormGroup variant="settings-group">
305+
<Label>Use Native Network Inspector Implementation</Label>
306+
<FormHelper>
307+
{launchConfigAttrs?.properties?.useNativeNetworkInspector?.description}
308+
</FormHelper>
309+
<SingleSelect
310+
data-testid="launch-configuration-use-native-network-inspector-select"
311+
name="useNativeNetworkInspector"
312+
initialValue={
313+
launchConfig?.useNativeNetworkInspector === undefined
314+
? ""
315+
: launchConfig.useNativeNetworkInspector
316+
? "true"
317+
: "false"
318+
}>
319+
<Option
320+
value=""
321+
data-testid="launch-configuration-use-native-network-inspector-select-detect-automatically">
322+
Detect automatically
323+
</Option>
324+
<Option
325+
value="true"
326+
data-testid="launch-configuration-use-native-network-inspector-select-yes">
327+
Yes
328+
</Option>
329+
<Option
330+
value="false"
331+
data-testid="launch-configuration-use-native-network-inspector-select-no">
332+
No
333+
</Option>
334+
</SingleSelect>
335+
</FormGroup>
336+
303337
<FormGroup variant="settings-group">
304338
<Label>Environment Variables</Label>
305339
<FormHelper>{launchConfigAttrs?.properties?.env?.description}</FormHelper>

0 commit comments

Comments
 (0)