Skip to content

Commit 83fbb0b

Browse files
motiz88meta-codesync[bot]
authored andcommitted
Track Network domain status in SessionState (#54068)
Summary: Pull Request resolved: #54068 Changelog: [Internal] Adds a `SessionState::isNetworkDomainEnabled` bit, managed in `HostAgent`, to align with other domains. Network support is still gated behind feature flags as before. Reviewed By: hoxyq Differential Revision: D83847357 fbshipit-source-id: 8f94c803d04256a7e41503f2a690e97b91e3ed5e
1 parent c24e67f commit 83fbb0b

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegate.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ class HermesRuntimeAgentDelegate::Impl final : public RuntimeAgentDelegate {
7272
}
7373

7474
bool handleRequest(const cdp::PreparsedRequest& req) override {
75-
// TODO: Change to string::starts_with when we're on C++20.
76-
if (req.method.rfind("Log.", 0) == 0) {
77-
// Since we know Hermes doesn't do anything useful with Log messages,
78-
// but our containing HostAgent will, bail out early.
75+
if (req.method.starts_with("Log.") || req.method.starts_with("Network.")) {
76+
// Since we know Hermes doesn't do anything useful with Log or Network
77+
// messages, but our containing HostAgent will, bail out early.
7978
// TODO: We need a way to negotiate this more dynamically with Hermes
8079
// through the API.
8180
return false;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "InstanceAgent.h"
1010

1111
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
12+
#include "InspectorFlags.h"
1213
#include "NetworkIOAgent.h"
1314
#include "SessionState.h"
1415
#include "TracingAgent.h"
@@ -142,6 +143,24 @@ class HostAgent::Impl final {
142143
.shouldSendOKResponse = true,
143144
};
144145
}
146+
if (InspectorFlags::getInstance().getNetworkInspectionEnabled()) {
147+
if (req.method == "Network.enable") {
148+
sessionState_.isNetworkDomainEnabled = true;
149+
150+
return {
151+
.isFinishedHandlingRequest = false,
152+
.shouldSendOKResponse = true,
153+
};
154+
}
155+
if (req.method == "Network.disable") {
156+
sessionState_.isNetworkDomainEnabled = false;
157+
158+
return {
159+
.isFinishedHandlingRequest = false,
160+
.shouldSendOKResponse = true,
161+
};
162+
}
163+
}
145164

146165
// Methods other than domain enables/disables: handle anything we know how
147166
// to handle, and delegate to the InstanceAgent otherwise. (In some special

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ bool NetworkIOAgent::handleRequest(
280280
if (req.method == "Network.enable") {
281281
networkHandler.setFrontendChannel(frontendChannel_);
282282
networkHandler.enable();
283-
frontendChannel_(cdp::jsonResult(req.id));
284-
return true;
283+
// NOTE: Domain enable/disable responses are sent by HostAgent.
284+
return false;
285285
}
286286

287287
// @cdp Network.disable support is experimental.
288288
if (req.method == "Network.disable") {
289289
networkHandler.disable();
290-
frontendChannel_(cdp::jsonResult(req.id));
291-
return true;
290+
// NOTE: Domain enable/disable responses are sent by HostAgent.
291+
return false;
292292
}
293293

294294
// @cdp Network.getResponseBody support is experimental.

packages/react-native/ReactCommon/jsinspector-modern/SessionState.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct SessionState {
2424
bool isLogDomainEnabled{false};
2525
bool isReactNativeApplicationDomainEnabled{false};
2626
bool isRuntimeDomainEnabled{false};
27+
bool isNetworkDomainEnabled{false};
2728

2829
/**
2930
* Whether the Trace Recording was initialized via CDP Tracing.start method

0 commit comments

Comments
 (0)