-
Notifications
You must be signed in to change notification settings - Fork 3
Add basic CDP support to inspector with Runtime and MyExample domains #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
…amples Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
yorkie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move cdp files to a separate directory: src/runtime/inspector/, also move the inspector_server and inspector_client to that directory, too.
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Done! I've moved all CDP and inspector files to
Changes committed in ddf322a. |
yorkie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces
| @@ -0,0 +1,157 @@ | |||
| #include "./cdp_handler.hpp" | |||
| #include "../common/debug.hpp" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #include "../common/debug.hpp" | |
| #include <common/debug.hpp> |
| using namespace std; | ||
|
|
||
| // CdpMessage implementation | ||
| std::unique_ptr<CdpMessage> CdpMessage::parse(const std::string& json) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| std::unique_ptr<CdpMessage> CdpMessage::parse(const std::string& json) { | |
| unique_ptr<CdpMessage> CdpMessage::parse(const string& json) { |
std should be removed if the namespace is using.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed! Removed std:: prefixes where using namespace std; is present. Changed std::unique_ptr to unique_ptr and std::string to string in function implementations. bcef284
… namespace std Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Fixed! Applied 2-space indentation throughout all CDP files using clang-format to match the project's coding standard. bcef284 Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use 2 spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed! Applied 2-space indentation throughout the JavaScript test client file. 58e567d
src/runtime/inspector.cpp
Outdated
|
|
||
| // Register CDP domains | ||
| cdpHandler_->registerDomain("Runtime", make_unique<CdpRuntimeDomain>(constellation)); | ||
| cdpHandler_->registerDomain("MyExample", make_unique<CdpMyExampleDomain>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cdpHandler_->registerDomain("MyExample", make_unique<CdpMyExampleDomain>()); | |
| cdpHandler_->registerDomain("Example", make_unique<CdpExampleDomain>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Changed "MyExample" to "Example" for cleaner domain naming. 58e567d
…actor protocol definition Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
yorkie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Only support upgrade the connection via /devtools/inspector/:client
- Example in fixtures should provide HTML instead of Node.js script, thus we can use browser to test the cdp implementation
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Implemented both requirements!
The enhanced HTML client provides complete CDP testing capabilities including domain-specific tests, custom message sending, and detailed validation - all accessible directly in the browser without Node.js dependencies. Changes in 508d6fb. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest message should be inserted at the top of the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed! The HTML test client now shows the latest messages at the top of the list using insertBefore() instead of appendChild(). This provides better usability as users can immediately see new activity without scrolling. Changes in e955247.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this document to the docs/internals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Moved the CDP support documentation from docs/cdp_support.md to docs/internals/cdp_support.md to better organize internal documentation. Changes in e955247.
| return CdpResponse::success(message.id, result); | ||
| } | ||
|
|
||
| void CdpMyExampleDomain::addProtocolDefinition(rapidjson::Value &domains, rapidjson::Document::AllocatorType &allocator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The domain name, description and commands could be declared in base class CdpDomainHandler thus the CdpHandler::addProtocolDefinitions could serialize the domain to JSON by itself.
At the specific domain handler such as CdpMyExampleDomain, it only needs to set the name, description and register commands only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent suggestion! Refactored the domain system to be more declarative. Domain handlers now implement simple methods (getDomainName(), getDomainDescription(), getCommands()) instead of manually building JSON. The CdpHandler::addProtocolDefinitions() method automatically serializes domain metadata to JSON, eliminating boilerplate code and improving maintainability. Changes in e955247.
…D support Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
|
|
||
| CdpHandler::~CdpHandler() = default; | ||
|
|
||
| string CdpHandler::processMessage(const string &message, const string &clientId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clientId parameter should be accessed at the each specific-domain message handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Modified the CdpDomainHandler base class and all domain implementations to pass the clientId parameter to the handleMethod() function. Domain handlers now receive the client ID extracted from the WebSocket path, enabling client-specific behavior and different handling for "server" vs specific client IDs. Changes committed in 3b478ec.
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This PR implements basic Chrome DevTools Protocol (CDP) support for the JSAR Runtime inspector, enabling CDP clients (such as Chrome DevTools) to connect via WebSocket and interact with the runtime.
Key Changes
Core CDP Infrastructure
CdpHandler- Main coordinator for CDP message processing with domain registryCdpMessage- Robust JSON parsing with validation and error handlingCdpResponse- Standardized response builder for success/error/event responsesCdpDomainHandler- Base class for extensible domain implementationsSample Domain Implementations
CdpRuntimeDomain- Runtime domain with JavaScript runtime methods:Runtime.enable- Enable runtime domainRuntime.disable- Disable runtime domainRuntime.getVersion- Get JavaScript runtime version informationRuntime.evaluate- Placeholder for script evaluationCdpMyExampleDomain- Example domain for testing connectivity:MyExample.ping- Simple connectivity test returning "pong"MyExample.echo- Echo back provided parametersMyExample.getInfo- Get domain information and available methodsEnhanced Inspector Integration
TrInspector::onMessage()to use CDP handler instead of simple echo/json/protocolendpoint with complete domain and method descriptionsTesting & Documentation
Protocol Compliance
The implementation follows CDP and JSON-RPC 2.0 standards:
Extensibility
The design enables easy addition of new domains:
Verification
To test the implementation:
make darwin INSPECTOR=yesnode fixtures/inspector-client/inspector_cdp_test_client.jscurl http://localhost:9423/json/protocolcurl http://localhost:9423/json/listThe implementation maintains backward compatibility while adding robust CDP support for modern debugging workflows.
Fixes #120.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
registry.npmmirror.comnpm install(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.