diff --git a/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp b/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp index a81d7b17667..b16d89395ae 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp @@ -47,7 +47,7 @@ class HostAgent::Impl final { hostMetadata_(std::move(hostMetadata)), sessionState_(sessionState), networkIOAgent_(NetworkIOAgent(frontendChannel, std::move(executor))), - tracingAgent_(TracingAgent(frontendChannel)) {} + tracingAgent_(TracingAgent(frontendChannel, sessionState)) {} ~Impl() { if (isPausedInDebuggerOverlayVisible_) { @@ -207,26 +207,6 @@ class HostAgent::Impl final { .shouldSendOKResponse = true, }; } - if (req.method == "Tracing.start") { - if (sessionState_.isDebuggerDomainEnabled) { - frontendChannel_(cdp::jsonError( - req.id, - cdp::ErrorCode::InternalError, - "Debugger domain is expected to be disabled before starting Tracing")); - - return { - .isFinishedHandlingRequest = true, - .shouldSendOKResponse = false, - }; - } - - // We delegate handling of this request to TracingAgent. If not handled, - // then something unexpected happened - don't send an OK response. - return { - .isFinishedHandlingRequest = false, - .shouldSendOKResponse = false, - }; - } return { .isFinishedHandlingRequest = false, diff --git a/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp b/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp index 0a3e365fd3d..d76e7632c77 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp @@ -31,9 +31,23 @@ const uint16_t PROFILE_TRACE_EVENT_CHUNK_SIZE = 1; } // namespace +TracingAgent::TracingAgent( + FrontendChannel frontendChannel, + const SessionState& sessionState) + : frontendChannel_(std::move(frontendChannel)), + sessionState_(sessionState) {} + bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) { if (req.method == "Tracing.start") { // @cdp Tracing.start support is experimental. + if (sessionState_.isDebuggerDomainEnabled) { + frontendChannel_(cdp::jsonError( + req.id, + cdp::ErrorCode::InternalError, + "Debugger domain is expected to be disabled before starting Tracing")); + + return true; + } if (!instanceAgent_) { frontendChannel_(cdp::jsonError( req.id, diff --git a/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.h b/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.h index 95ed57efc45..f58e01f2683 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.h @@ -25,8 +25,9 @@ class TracingAgent { * \param frontendChannel A channel used to send responses to the * frontend. */ - explicit TracingAgent(FrontendChannel frontendChannel) - : frontendChannel_(std::move(frontendChannel)) {} + TracingAgent( + FrontendChannel frontendChannel, + const SessionState& sessionState); /** * Handle a CDP request. The response will be sent over the provided @@ -60,6 +61,8 @@ class TracingAgent { * in this trace. */ HighResTimeStamp instanceTracingStartTimestamp_; + + const SessionState& sessionState_; }; } // namespace facebook::react::jsinspector_modern