From 6fd2cc27f8d41e7d556fa026eac1f77ab4831ec2 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Mon, 10 Nov 2025 06:27:13 -0800 Subject: [PATCH] Update Network and Tracing handlers to error under multiple hosts (#54408) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54408 Follows from the parent commit. This will prevent 3P CDP clients from using the `Tracing` or `Network` domains when we are in an unsupported multi React Native Host setup. Changelog: [Internal] Reviewed By: hoxyq Differential Revision: D86201688 fbshipit-source-id: 052d563a371fd77c1a05ad8518e222d6bc1eb372 --- .../jsinspector-modern/HostAgent.cpp | 17 ++++++++++++++--- .../jsinspector-modern/TracingAgent.cpp | 12 +++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp b/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp index 9464d625695..813770d51ad 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp @@ -146,6 +146,19 @@ class HostAgent::Impl final { } if (InspectorFlags::getInstance().getNetworkInspectionEnabled()) { if (req.method == "Network.enable") { + auto& inspector = getInspectorInstance(); + if (inspector.getSystemState().registeredPagesCount > 1) { + frontendChannel_( + cdp::jsonError( + req.id, + cdp::ErrorCode::InternalError, + "The Network domain is unavailable when multiple React Native hosts are registered.")); + return { + .isFinishedHandlingRequest = true, + .shouldSendOKResponse = false, + }; + } + sessionState_.isNetworkDomainEnabled = true; return { @@ -386,9 +399,7 @@ class HostAgent::Impl final { "ReactNativeApplication.systemStateChanged", folly::dynamic::object("isSingleHost", isSingleHost))); - if (!isSingleHost) { - frontendChannel_(cdp::jsonNotification("Network.disable")); - } + frontendChannel_(cdp::jsonNotification("Network.disable")); } private: diff --git a/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp b/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp index e661b0e741a..823c56ecfaa 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp @@ -53,7 +53,17 @@ TracingAgent::~TracingAgent() { bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) { if (req.method == "Tracing.start") { - // @cdp Tracing.start support is experimental. + auto& inspector = getInspectorInstance(); + if (inspector.getSystemState().registeredPagesCount > 1) { + frontendChannel_( + cdp::jsonError( + req.id, + cdp::ErrorCode::InternalError, + "The Tracing domain is unavailable when multiple React Native hosts are registered.")); + + return true; + } + if (sessionState_.isDebuggerDomainEnabled) { frontendChannel_( cdp::jsonError(