Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(dev-middleware): add enableNetworkInspector experiment #41787

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dev-middleware/src/createDevMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ function getExperiments(config: ExperimentsConfig): Experiments {
return {
enableNewDebugger: config.enableNewDebugger ?? false,
enableOpenDebuggerRedirect: config.enableOpenDebuggerRedirect ?? false,
enableNetworkInspector: config.enableNetworkInspector ?? false,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function openDebuggerMiddleware({
app =>
app.title === 'React Native Experimental (Improved Chrome Reloads)',
);

let target;

const launchType: 'launch' | 'redirect' =
Expand Down Expand Up @@ -117,6 +118,7 @@ export default function openDebuggerMiddleware({
frontendInstanceId,
await browserLauncher.launchDebuggerAppWindow(
getDevToolsFrontendUrl(
experiments,
target.webSocketDebuggerUrl,
serverBaseUrl,
),
Expand All @@ -127,6 +129,7 @@ export default function openDebuggerMiddleware({
case 'redirect':
res.writeHead(302, {
Location: getDevToolsFrontendUrl(
experiments,
target.webSocketDebuggerUrl,
// Use a relative URL.
'',
Expand Down
6 changes: 6 additions & 0 deletions packages/dev-middleware/src/types/Experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export type Experiments = $ReadOnly<{
* interface.
*/
enableOpenDebuggerRedirect: boolean,

/**
* Enables the new JS debugger network panel and network CDP events.
* When disabled, all CDP events and the network panel are disabled.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Which CDP events does this enable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since its missing at the moment, none. But, on Expo's side we can use this to enable/disable two non-trivial CDP events:

Custom Expo(Network.receivedResponseBody)

This event offloads the responses to the inspector proxy when received by the app. When we need to respond to Network.getResponseBody, we need to be able to reply to it. That's not something we could implement on the native side, we can only send from the native side (not receive events).

Because of that, once a user opens the app, all network responses are logged to the CLI process. Meaning that there will be quite a build-up in memory over time, without any event being able to clear this.

Network.getResponseBody

This just pulls the data received earlier from the device, and sends it to the debugger.

byCedric marked this conversation as resolved.
Show resolved Hide resolved
*/
enableNetworkInspector: Boolean,
byCedric marked this conversation as resolved.
Show resolved Hide resolved
}>;

export type ExperimentsConfig = Partial<Experiments>;
9 changes: 8 additions & 1 deletion packages/dev-middleware/src/utils/getDevToolsFrontendUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
* @oncall react_native
*/

import type {Experiments} from '../types/Experiments';

/**
* Get the DevTools frontend URL to debug a given React Native CDP target.
*/
export default function getDevToolsFrontendUrl(
experiments: Experiments,
webSocketDebuggerUrl: string,
devServerUrl: string,
): string {
Expand All @@ -22,5 +25,9 @@ export default function getDevToolsFrontendUrl(
webSocketDebuggerUrl.replace(/^wss?:\/\//, ''),
);

return `${appUrl}?${scheme}=${webSocketUrlWithoutProtocol}&sources.hide_add_folder=true`;
const devToolsUrl = `${appUrl}?${scheme}=${webSocketUrlWithoutProtocol}&sources.hide_add_folder=true`;

return experiments.enableNetworkInspector
? `${devToolsUrl}&unstable_enableNetworkPanel=true`
: devToolsUrl;
}
Loading