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
This commit is contained in:
Alex Hunt authored and Alex Hunt committed 2025-11-11 11:25:35 +00:00
1 parent 74d687c213
commit 6fd2cc27f8
2 files changed
+25 -4

No files matched your search

@@ -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:
@@ -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(