Skip to content

Commit a9d13f3

Browse files
huntiemeta-codesync[bot]
authored andcommitted
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 d1944f1 commit a9d13f3

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: 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ TracingAgent::~TracingAgent() {
4949

5050
bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
5151
if (req.method == "Tracing.start") {
52+
auto& inspector = getInspectorInstance();
53+
if (inspector.getSystemState().registeredPagesCount > 1) {
54+
frontendChannel_(
55+
cdp::jsonError(
56+
req.id,
57+
cdp::ErrorCode::InternalError,
58+
"The Tracing domain is unavailable when multiple React Native hosts are registered."));
59+
60+
return true;
61+
}
62+
5263
if (sessionState_.isDebuggerDomainEnabled) {
5364
frontendChannel_(
5465
cdp::jsonError(

0 commit comments

Comments
 (0)