Skip to content

Commit

Permalink
Add ReactNativeApplication CDP domain (#44894)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #44894

Adds the new CDP domain `ReactNativeApplication`, with the following messages:

- `ReactNativeApplication.enable` (method) — Sent by the connected frontend to enable features under this domain.
- `ReactNativeApplication.metadataUpdated` (event) — Sent by the backend containing a metadata object about the host.

We intend to use this for displaying richer information in the debugger frontend, such as device information and React Native version.

Changelog:
[General][Added] - Add `ReactNativeApplication.[enable,metadataUpdated]` CDP messages for reading host metadata

Reviewed By: motiz88

Differential Revision: D58288490

fbshipit-source-id: 02384f0cdfaa35f1c5de9fad7ddd5aab483b2768
  • Loading branch information
huntie authored and facebook-github-bot committed Jun 12, 2024
1 parent 28ded2c commit aced407
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ void HostAgent::handleRequest(const cdp::PreparsedRequest& req) {
sendFuseboxNotice();
}

shouldSendOKResponse = true;
isFinishedHandlingRequest = true;
} else if (req.method == "ReactNativeApplication.enable") {
sessionState_.isReactNativeApplicationDomainEnabled = true;

frontendChannel_(cdp::jsonNotification(
"ReactNativeApplication.metadataUpdated",
hostMetadataToDynamic(hostMetadata_)));

shouldSendOKResponse = true;
isFinishedHandlingRequest = true;
} else if (req.method == "ReactNativeApplication.disable") {
sessionState_.isReactNativeApplicationDomainEnabled = false;

shouldSendOKResponse = true;
isFinishedHandlingRequest = true;
} else if (req.method == "Tracing.start") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,12 @@ bool HostTargetController::decrementPauseOverlayCounter() {
return true;
}

folly::dynamic hostMetadataToDynamic(const HostTargetMetadata& metadata) {
folly::dynamic result = folly::dynamic::object;

result["integrationName"] = metadata.integrationName.value_or(nullptr);

return result;
}

} // namespace facebook::react::jsinspector_modern
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,6 @@ class JSINSPECTOR_EXPORT HostTarget
friend class HostTargetController;
};

folly::dynamic hostMetadataToDynamic(const HostTargetMetadata& metadata);

} // namespace facebook::react::jsinspector_modern
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct SessionState {
// TODO: Generalise this to arbitrary domains
bool isDebuggerDomainEnabled{false};
bool isLogDomainEnabled{false};
bool isReactNativeApplicationDomainEnabled{false};
bool isRuntimeDomainEnabled{false};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,42 @@ TYPED_TEST(JsiIntegrationPortableTest, FuseboxSetClientMetadata) {
})");
}

TYPED_TEST(JsiIntegrationPortableTest, ReactNativeApplicationEnable) {
this->connect();

this->expectMessageFromPage(JsonEq(R"({
"id": 1,
"result": {}
})"));
this->expectMessageFromPage(JsonEq(R"({
"method": "ReactNativeApplication.metadataUpdated",
"params": {
"integrationName": "JsiIntegrationTest"
}
})"));

this->toPage_->sendMessage(R"({
"id": 1,
"method": "ReactNativeApplication.enable",
"params": {}
})");
}

TYPED_TEST(JsiIntegrationPortableTest, ReactNativeApplicationDisable) {
this->connect();

this->expectMessageFromPage(JsonEq(R"({
"id": 1,
"result": {}
})"));

this->toPage_->sendMessage(R"({
"id": 1,
"method": "ReactNativeApplication.disable",
"params": {}
})");
}

#pragma endregion // AllEngines
#pragma region AllHermesVariants

Expand Down

0 comments on commit aced407

Please sign in to comment.