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 all commits
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
5 changes: 5 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,11 @@ export type Experiments = $ReadOnly<{
* interface.
*/
enableOpenDebuggerRedirect: boolean,

/**
* Enables the Network panel when launching the custom debugger frontend.
*/
enableNetworkInspector: boolean,
}>;

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