-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
[WIP] Node support for the inspector "Target" domain #16629
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
62193ba
inspector: add support for protocol extension
d5124bd
inspector: add 'Target' domain handler
962c616
inspector: No built-in domain override
926a5c2
WIP - addressing code review comments, to be squashed.
3901aa5
(To be squashed) Reject malformed method name
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Extending Node.js Inspector Protocol | ||
|
||
Node.js Inspector Protocol (based on the [Chrome DevTools](https://chromedevtools.github.io/devtools-protocol/v8/)) | ||
is designed to be easily extensible by the implementers. This document provides | ||
details on such extension. | ||
|
||
## Terminology | ||
|
||
* *Inspector session* - message exchange between protocol client and Node.js | ||
* *Protocol handler* - object with a lifetime of the inspector session that | ||
interacts with the protocol client. | ||
* *Protocol domain* - 'API unit' of the inspector protocol. Defines message | ||
formats for specific and related functionality. Node.js exposes protocol | ||
domains provided by the V8. These include `Runtime`, `Debugger`, `Profiler` and | ||
`HeapProfiler`. | ||
* *Message* - a JSON string passed between Node.js backend and an inspector | ||
protocol client. Message types are: request, response and notification. Protocol | ||
client only sends out requests. Messages are asynchronous and client should not | ||
assume response will be sent immediately after serving the request. | ||
* *Method field* - a mandatory field in request and notification messages. | ||
This field value includes *domain* and *method* strings separated by a dot | ||
(e.g. `Debugger.pause`). | ||
|
||
## API | ||
|
||
`internal/inspector_node_domains` module provides API for extending inspector | ||
protocol exposed by the Node.js | ||
|
||
### inspector_node_domains.registerDomainHandlerClass(domain, constructor) | ||
|
||
* domain {string} - a JavaScript identifier string that serves as a unique | ||
identifier for the messages that target this domain. Domains should be unique. | ||
It is not permitted to override built-in Node.js domains. | ||
* constructor {ES6 class|constructor function} - creates a protocol handler that | ||
will receive messages for the specified domain. This function should accept a | ||
single callback argument. This callback can be used by the handler to send | ||
notifications to protocol clients. Callback accepts two arguments - *method* and | ||
optional *parameters* object. This callback can be called multiple times. | ||
|
||
### Handler method | ||
|
||
Protocol dispatcher will call handler method with the name that was specified in | ||
the *method field*. Handler method will receive message *params* object as an | ||
argument. Handler method can return one of the following: | ||
* Nothing. Empty response will be sent to the client. | ||
* Object. This object will be sent to the client as *params* field of | ||
the response. | ||
* Throw exception. Error response will be sent to the client. Exception message | ||
will be included in the response. In the case thrown object does not have the | ||
message field, entire object will be included in the response. | ||
* Function that accepts a callback argument. This function will be invoked | ||
immediately by the dispatcher and enables asynchronous processing of | ||
the inspector message. | ||
|
||
### [SessionTerminatedSymbol] handler method | ||
|
||
This method is invoked when inspector session is terminated and should perform | ||
all necessary cleanup. | ||
|
||
## Things to keep in mind | ||
|
||
Regular event loop is interrupted to process the protocol message. This is to | ||
ensure that tooling is available even while the application is running a | ||
continuous body of code (e.g. infinite loop) or is waiting for IO events. | ||
|
||
This means that the handler implementation should be careful when relying on | ||
async APIs (e.g. promise resolution) as those events may never happen if | ||
the user code is stuck in the infinite loop or if the JavaScript VM is paused on | ||
a breakpoint. | ||
|
||
## Being a good citizen | ||
|
||
* Any state should not outlive the session state. E.g. event collection should | ||
be disabled, buffers should be freed. | ||
* Handlers should never be initiating the exchange. E.g. handlers should not | ||
send any notifications before the client explicitly requests them. Convention | ||
is to only send notification after the client invokes '*Domain*.enable' method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just a reminder that bothES6 class
andconstructor function
need to be added in type-parser.jsThere 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.
fwiw this isn’t part of the external API documentation