|
9 | 9 | #include <folly/json.h> |
10 | 10 | #include <jsinspector-modern/PageAgent.h> |
11 | 11 |
|
| 12 | +#include <chrono> |
| 13 | + |
| 14 | +using namespace std::chrono; |
| 15 | +using namespace std::literals::string_view_literals; |
| 16 | + |
12 | 17 | namespace facebook::react::jsinspector_modern { |
13 | 18 |
|
| 19 | +#define ANSI_WEIGHT_BOLD "\x1B[1m" |
| 20 | +#define ANSI_WEIGHT_RESET "\x1B[22m" |
| 21 | +#define ANSI_STYLE_ITALIC "\x1B[3m" |
| 22 | +#define ANSI_STYLE_RESET "\x1B[23m" |
| 23 | +#define ANSI_COLOR_BG_YELLOW "\x1B[48;2;253;247;231m" |
| 24 | + |
| 25 | +static constexpr auto kModernCDPBackendNotice = |
| 26 | + ANSI_COLOR_BG_YELLOW ANSI_WEIGHT_BOLD |
| 27 | + "NOTE:" ANSI_WEIGHT_RESET " You are using the " ANSI_STYLE_ITALIC |
| 28 | + "modern" ANSI_STYLE_RESET " CDP backend for React Native (PageTarget)."sv; |
| 29 | + |
14 | 30 | PageAgent::PageAgent(FrontendChannel frontendChannel) |
15 | 31 | : frontendChannel_(frontendChannel) {} |
16 | 32 |
|
17 | 33 | void PageAgent::handleRequest(const cdp::PreparsedRequest& req) { |
| 34 | + if (req.method == "Log.enable") { |
| 35 | + // Send an "OK" response. |
| 36 | + frontendChannel_( |
| 37 | + folly::toJson(folly::dynamic::object("id", req.id)("result", nullptr))); |
| 38 | + |
| 39 | + // Send a log entry identifying the modern CDP backend. |
| 40 | + frontendChannel_( |
| 41 | + folly::toJson(folly::dynamic::object("method", "Log.entryAdded")( |
| 42 | + "params", |
| 43 | + folly::dynamic::object( |
| 44 | + "entry", |
| 45 | + folly::dynamic::object( |
| 46 | + "timestamp", |
| 47 | + duration_cast<milliseconds>( |
| 48 | + system_clock::now().time_since_epoch()) |
| 49 | + .count())("source", "other")( |
| 50 | + "level", "info")("text", kModernCDPBackendNotice))))); |
| 51 | + |
| 52 | + return; |
| 53 | + } |
18 | 54 | folly::dynamic res = folly::dynamic::object("id", req.id)( |
19 | 55 | "error", |
20 | 56 | folly::dynamic::object("code", -32601)( |
|
0 commit comments