Skip to content

Commit 1f3926b

Browse files
huntiefacebook-github-bot
authored andcommitted
Update Network and Tracing handlers to error under multiple hosts
Summary: 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] Differential Revision: D86201688
1 parent d6380e4 commit 1f3926b

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ class HostAgent::Impl final {
146146
}
147147
if (InspectorFlags::getInstance().getNetworkInspectionEnabled()) {
148148
if (req.method == "Network.enable") {
149+
if (!InspectorSystemState::getInstance().isSingleHost()) {
150+
frontendChannel_(
151+
cdp::jsonError(
152+
req.id,
153+
cdp::ErrorCode::InternalError,
154+
"The Network domain is unavailable when multiple React Native hosts are registered."));
155+
return {
156+
.isFinishedHandlingRequest = true,
157+
.shouldSendOKResponse = false,
158+
};
159+
}
160+
149161
sessionState_.isNetworkDomainEnabled = true;
150162

151163
return {
@@ -384,9 +396,7 @@ class HostAgent::Impl final {
384396
"ReactNativeApplication.systemStateChanged",
385397
folly::dynamic::object("isSingleHost", isSingleHost)));
386398

387-
if (!isSingleHost) {
388-
frontendChannel_(cdp::jsonNotification("Network.disable"));
389-
}
399+
frontendChannel_(cdp::jsonNotification("Network.disable"));
390400
}
391401

392402
private:

packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "TracingAgent.h"
99

10+
#include "InspectorSystemState.h"
11+
1012
#include <jsinspector-modern/tracing/PerformanceTracer.h>
1113
#include <jsinspector-modern/tracing/RuntimeSamplingProfileTraceEventSerializer.h>
1214
#include <jsinspector-modern/tracing/TraceEventSerializer.h>
@@ -53,6 +55,16 @@ TracingAgent::~TracingAgent() {
5355

5456
bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
5557
if (req.method == "Tracing.start") {
58+
if (!InspectorSystemState::getInstance().isSingleHost()) {
59+
frontendChannel_(
60+
cdp::jsonError(
61+
req.id,
62+
cdp::ErrorCode::InternalError,
63+
"The Tracing domain is unavailable when multiple React Native hosts are registered."));
64+
65+
return true;
66+
}
67+
5668
if (sessionState_.isDebuggerDomainEnabled) {
5769
frontendChannel_(
5870
cdp::jsonError(

0 commit comments

Comments
 (0)