nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.56k stars 29.05k forks source link

Tracking issue: Stabilizing network inspection in Node.js #53946

Open cola119 opened 1 month ago

cola119 commented 1 month ago

Related issue: https://github.com/nodejs/diagnostics/issues/75 Initial implementation: https://github.com/nodejs/node/pull/53593

This issue is for tracking the remaining work to make network inspection in Node.js stable and to provide a comprehensive debugging experience.

Network inspection features

Basic information

Feature http https http2 fetch WebSocket
type ✅ #54156 ✅ #54156
timestamp ✅ #53593 ✅ #53593
error ✅ #54246 ✅ #54246

Related protocols:

Request details

The details of the request, such as the request body, cookies, and query parameters. The Network.Request object is used to represent the request. Some features such as referrerPolicy are only available in browser contexts.

Feature http https http2 fetch WebSocket
url ✅ #53593 ✅ #53593
method ✅ #53593 ✅ #53593
headers ✅ #54156 ✅ #54156
postData 🔍 🔍

Related protocols:

🔍 Response details

The details of the response, such as the response body, and headers. The Network.Response object is used to represent the response. Some features such as early hits are only available for browser contexts.

Feature http https http2 fetch WebSocket
url ✅ #54156 ✅ #54156
status ✅ #54156 ✅ #54156
headers ✅ #54156 ✅ #54156
mimeType

[!CAUTION] We can't consume the response body within the diagnostics_channel hook. We need to investigate how to handle the response body. (ref. https://github.com/nodejs/node/pull/53593#discussion_r1658039637)

Related protocols:

🔍 Request initiator

The initiator of the request, such as the script URL, the line number, and the stack trace. The Network.Initiator object is used to represent the initiator.

Feature http https http2 fetch WebSocket
initiator

Related protocols:

🚫 Network conditions and throttling

The network conditions and throttling information of the request and response. The Network.emulateNetworkConditions command is used to emulate network conditions.

🚫 Security and authentication information

The security and authentication information of the request and response. The SecurityDetails object is used to represent the security details.

Others

If there are any other features that are not covered by the above categories, please let us know and we will add them to the list.

Node.js specific features

These are network inspection features specific to Node.js applications, including:

These features are not available in the browser context. We plan to support these features in collaboration with the ChromeDevTools team. To move forward with the implementation, we will create a design doc for these features and discuss the specs with the ChromeDevTools team.

Next steps

cola119 commented 1 month ago

Investigation of WebSocket support

Events

1. Network.webSocketCreated

Fired upon WebSocket creation.

Can this event be hooked? 🟢 (The undici:websocket:open diagnostics channel)

parameter description Can it be collected? Note
requestId Request identifier. 🟢
url WebSocket request URL. 🟢 Available in the undici:websocket:open diagnostics channel
initiator The name of the initiator.

2. Network.webSocketWillSendHandshakeRequest

Fired when WebSocket is about to initiate handshake.

Can this event be hooked? ❌ (No diagnostics channel)

parameter description Can it be collected? Note
requestId Request identifier. 🟢
timestamp Timestamp. 🟢
wallTime Timestamp. 🟢
request WebSocket request. See Network.WebSocketRequest

3. Network.webSocketHandshakeResponseReceived

Fired when WebSocket handshake response becomes available.

Can this event be hooked? ❌ (No diagnostics channel)

parameter description Can it be collected? Note
requestId Request identifier. 🟢
timestamp Timestamp. 🟢
response WebSocket response. See Network.WebSocketResponse

4. Network.webSocketFrameSent

Fired when WebSocket frame is sent.

Can this event be hooked? ❌ (No diagnostics channel)

parameter description Can it be collected? Note
requestId Request identifier 🟢
timestamp Timestamp 🟢
response WebSocket response See Network.WebSocketFrame

5. Network.webSocketFrameReceived

Fired when WebSocket frame is received.

Can this event be hooked? ❌ (No diagnostics channel)

parameter description Can it be collected? Note
requestId Request identifier. 🟢
timestamp Timestamp. 🟢
response WebSocket response. See Network.WebSocketFrame

6. Network.webSocketFrameError

Fired when WebSocket frame error occurs.

Can this event be hooked? ❌ (The undici:websocket:socket_error diagnostics channel is insufficient for collecting all necessary data)

parameter description Can it be collected? Note
requestId Request identifier. 🟢
timestamp Timestamp. 🟢
errorMessage Error message.

7. Network.webSocketClosed

Fired when WebSocket is closed.

Can this event be hooked? 🟢 (The undici:websocket:close diagnostics channel)

parameter description Can it be collected? Note
requestId Request identifier. 🟢
timestamp Timestamp. 🟢

Network.WebSocketRequest

Collectibility of the following data depends on the implementation of diagnostics channels.

parameter description Can it be collected? Note
headers HTTP request headers

Types

Network.WebSocketResponse

Collectibility of the following data depends on the implementation of diagnostics channels.

parameter description Can it be collected? Note
status HTTP response status.
statusText HTTP response status text.
headers HTTP response headers.
headersText HTTP response headers text.
requestHeaders HTTP request headers.
requestHeadersText HTTP request headers text.

Network.WebSocketFrame

Collectibility of the following data depends on the implementation of diagnostics channels.

parameter description Can it be collected? Note
opcode WebSocket opcode.
mask WebSocke mask.
payloadData WebSocket payload data.
GrinZero commented 1 month ago

mark