Skip to content

Commit 6fd2cc2

Browse files
committed
Update Network and Tracing handlers to error under multiple hosts (#54408)
Summary: Pull Request resolved: #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
1 parent 74d687c commit 6fd2cc2

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

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

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

151164
return {
@@ -386,9 +399,7 @@ class HostAgent::Impl final {
386399
"ReactNativeApplication.systemStateChanged",
387400
folly::dynamic::object("isSingleHost", isSingleHost)));
388401

389-
if (!isSingleHost) {
390-
frontendChannel_(cdp::jsonNotification("Network.disable"));
391-
}
402+
frontendChannel_(cdp::jsonNotification("Network.disable"));
392403
}
393404

394405
private:

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@ TracingAgent::~TracingAgent() {
5353

5454
bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
5555
if (req.method == "Tracing.start") {
56-
// @cdp Tracing.start support is experimental.
56+
auto& inspector = getInspectorInstance();
57+
if (inspector.getSystemState().registeredPagesCount > 1) {
58+
frontendChannel_(
59+
cdp::jsonError(
60+
req.id,
61+
cdp::ErrorCode::InternalError,
62+
"The Tracing domain is unavailable when multiple React Native hosts are registered."));
63+
64+
return true;
65+
}
66+
5767
if (sessionState_.isDebuggerDomainEnabled) {
5868
frontendChannel_(
5969
cdp::jsonError(

0 commit comments

Comments
 (0)