You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Network domain is what Chrome DevTools (and any other interested frontends) use for inspecting the HTTP and WS traffic in the browser. This document provides some insight into Chrome DevTools UI and here is a description of the protocol for obtaining that data.
We propose to introduce a Node specific agent that would expose the same (or subset) of this protocol to enable the UI. It does not seem possible to share the implementation between Blink and Node.js.
This agent would also introduce an API for the modules to report the events. E.g. WebSocket modules should be able to notify the agent when WS frames are sent or received.
Would it make sense to use trace events as the interface to the agent? That would also provide an interface for 3rd party modules (e.g. Websocket) out-of-the-box.
I'm not sure if tcp/udp would become confusing because it's another level than the others. Would http requests show up twice effectively? But having a story for things like memcached's TCP protocol would be great. The obvious/hacky solution would be for them to pretend to be websocket frames.
Looks like trace events might be usable for this. HTTP requests/responses might get quite big - I wonder if there's any limit on event sizes...
+@matthewloring, @ofrobots - would it be possible to use the trace events framework for this? E.g. inspector would have an agent that "listens" on event categories and then sends inspector protocol notifications.
One thing I ran into with a similar feature in bugger: Retaining all request and response bodies in the process can become problematic, especially when there's no easy way to disable it. E.g. "hey let me profile this app while sending a couple of thousand of requests through it to find that memory leak" - aaand you're running out of memory because all request/response bodies are being kept in memory by the agent.
There is not currently a mechanism for observing trace events as they are generated. We could explore this in the future once the design in nodejs/node#9304 solidifies.
My architecture proposal in nodejs/node#7393 is largely about allowing implementation of Domain.Method dispatchers other than those tied directly to V8, which is all we have now. The Network domain implementation we're discussing in this thread could be handled by just such an alternate dispatcher if our architecture allowed it.
Allowing alternate dispatchers would a) allow complete alternate implementations, e.g. for other runtimes like Chakra or SpiderMonkey; and b) facilitate one-off (monkey-patched?) alternate or additional implementations for specific Domains and Methods.
/cc @kfarnung who's been looking into such a rearchitecture and Inspector's impact on e.g. Node-ChakraCore more deeply.
Perhaps a way to facilitate inspector "addons" would be to update NodeInspectorClient::dispatchMessageFromFrontend to route based on the Domain name. That is, Debugger, Profiler, Runtime, and all the domains handled by V8 would be routed to V8Inspector as they are now; and others like Network could be routed elsewhere.
Was there any movement on this? I think it would be a really great feature. It looks like in Chrome there's a pretty straight-forward check (InspectorSession::DispatchProtocolMessage):
We could "just" introduce an extension to the existing inspector JS API that allows to register additional handlers. Or, alternatively, a C++ API for the same (might be less confusing when it comes to execution / threads).
The idea here is that we could start with opening up an experimental low-level API and then later decide if and what kind of node-specific dispatchers we'd want.
Right now I am working on custom protocol handlers on the Node side. I am implementing "Target" domain (that should allow debugging child processes). "Network" domain can be implemented afterwards, but it would require effort from module writers - e.g. WebSocket implementors will need to specifically report WS frames.
As @mcollina asked, the Network panel in the browser's DevTools always represents client-side traffic. In Node.js, a server may both received and send requests, which has to be represented in the Network tab somehow.
Proposal: follow @nicoburns suggestion #75 (comment) and add both incoming/outgoing traffic in the Network. I'm not aware if CDP supports custom tags for network entries so we could have a checkbox to filter out different kinds of traffic.
How to record the traffic?
I appreciate different third-party suggestions (proxies/interception libraries) but I believe the most straightforward way to do that would be using node:async_hooks and its HTTPINCOMINGMESSAGE and HTTPOUTGOINGMESSAGE events.
One must consider, however, that if a Node.js process has its request modules patches (e.g. when running tests that use API mocking solutions, those events will likely not be called by async_hooks. I believe there is also a tremendous value in being able to inspect mocked network, but for that to work we'd have to spy on higher-level request modules, like http. Once can use Proxy to do that in the least intrusive way possible.
What's to be done?
I have very little knowledge in the CDP but it looks like this is a rough roadmap:
Node.js has to implement the Network domain of the CDP.
Node.js has to use the Network domain to register outgoing/incoming requests based on the async_hooks listeners (such as invoking .requestWillBeSent() for an requests and .responseReceived() for responses).
Node.js has to differentiate between the outgoing and incoming requests somehow.
Tests.
Questions
@mcollina, to your best knowledge, does async_hooks provide sufficient data to be fed to the Network domain of the devtools? Is there any data that's missing/won't be observable?
I suppose with the WebSocket API landing natively in Node.js it will support async_hooks as well? Otherwise it won't be observable.
How to deal with third-party WebSocket implementations, if at all? Userland will take time to migrate to the standard WebSocket API, and until then, they will rely on Socket, I assume. It's observable in async_hooks, as far as I recall. Does that sound like a reliable strategy for implementing WebSocket support in the Network inspector?
Reacted by Patrick Kerschbaum, Kohei and Haroen Viaene
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.
Reacted by starball, Gabriel De Andrade and Ben Watkins
Expect to be able to listen to requests with chrome devtools made by your own program? You can refer to my recently developed open source library: https://github.com/GrinZero/node-network-devtools.
It edit the 'http' and 'https' module from your node program and use CDP to show the info in chrome devtools.
I also hope that the official can support it. It's exhausting to do this myself.
I hope nodejs/node#53593 can be a starting point to discuss how we can realize network inspection. If you have any suggestions, please feel free to share them!
The feature is now available with an experimental flag --experimental-network-inspection. Closing and track the experiment status in nodejs/node#53946.
Reacted by Patrick Kerschbaum, Charles Xu, Mark Fulton, Darshan Sen, Kohei and Brian Mortenson
Activity
sidorares commentedon Dec 1, 2016
would be great to have support for node tcp/udp as well, not sure if that can fit into existing UI and debugger protocol
hybrist commentedon Dec 1, 2016
Would it make sense to use trace events as the interface to the agent? That would also provide an interface for 3rd party modules (e.g. Websocket) out-of-the-box.
I'm not sure if tcp/udp would become confusing because it's another level than the others. Would http requests show up twice effectively? But having a story for things like memcached's TCP protocol would be great. The obvious/hacky solution would be for them to pretend to be websocket frames.
eugeneo commentedon Dec 1, 2016
Looks like trace events might be usable for this. HTTP requests/responses might get quite big - I wonder if there's any limit on event sizes...
+@matthewloring, @ofrobots - would it be possible to use the trace events framework for this? E.g. inspector would have an agent that "listens" on event categories and then sends inspector protocol notifications.
hybrist commentedon Dec 2, 2016
One thing I ran into with a similar feature in bugger: Retaining all request and response bodies in the process can become problematic, especially when there's no easy way to disable it. E.g. "hey let me profile this app while sending a couple of thousand of requests through it to find that memory leak" - aaand you're running out of memory because all request/response bodies are being kept in memory by the agent.
matthewloring commentedon Dec 2, 2016
There is not currently a mechanism for observing trace events as they are generated. We could explore this in the future once the design in nodejs/node#9304 solidifies.
alnorris commentedon Feb 24, 2017
Would it be possible to monkey patch this? Similar to how node inspector does it?
paulirish commentedon Feb 26, 2017
@alnorris honestly it looks like the existing monkeypatch from node-inspector (Injections/NetworkAgent.js) would get pretty far.
The emitted events would just need to make their way to the InspectorAgent
joshgav commentedon Feb 27, 2017
My architecture proposal in nodejs/node#7393 is largely about allowing implementation of Domain.Method dispatchers other than those tied directly to V8, which is all we have now. The Network domain implementation we're discussing in this thread could be handled by just such an alternate dispatcher if our architecture allowed it.
Allowing alternate dispatchers would a) allow complete alternate implementations, e.g. for other runtimes like Chakra or SpiderMonkey; and b) facilitate one-off (monkey-patched?) alternate or additional implementations for specific Domains and Methods.
/cc @kfarnung who's been looking into such a rearchitecture and Inspector's impact on e.g. Node-ChakraCore more deeply.
joshgav commentedon May 11, 2017
Perhaps a way to facilitate inspector "addons" would be to update NodeInspectorClient::dispatchMessageFromFrontend to route based on the Domain name. That is, Debugger, Profiler, Runtime, and all the domains handled by V8 would be routed to V8Inspector as they are now; and others like Network could be routed elsewhere.
[-]Support for HTTP/WS inspection[/-][+]Support Network Inspection[/+]joshgav commentedon May 11, 2017
@eugeneo I changed the title so it would be more obvious what this issue is about, please change back if you disagree. Thanks!
eugeneo commentedon May 11, 2017
@joshgav I agree. I want to look into JS handlers for the inspector messages. Currently I am waiting for the inspector JS API PR to land.
hybrist commentedon Oct 24, 2017
Was there any movement on this? I think it would be a really great feature. It looks like in Chrome there's a pretty straight-forward check (
InspectorSession::DispatchProtocolMessage):We could "just" introduce an extension to the existing inspector JS API that allows to register additional handlers. Or, alternatively, a C++ API for the same (might be less confusing when it comes to execution / threads).
The idea here is that we could start with opening up an experimental low-level API and then later decide if and what kind of node-specific dispatchers we'd want.
eugeneo commentedon Oct 24, 2017
Right now I am working on custom protocol handlers on the Node side. I am implementing "Target" domain (that should allow debugging child processes). "Network" domain can be implemented afterwards, but it would require effort from module writers - e.g. WebSocket implementors will need to specifically report WS frames.
eugeneo commentedon Oct 24, 2017
@jkrems - this is the Node counterpart - https://github.com/eugeneo/node/blob/df8e41d3be705410e3a3389b8660b3289e25399f/src/inspector_agent.cc#L255
Minor difference is that I am passing unrecognized messages to V8 dispatcher to reuse "method not found" notification.
47 remaining items
quantuminformation commentedon Sep 11, 2023
kettanaito commentedon Dec 14, 2023
Sharing my thoughts on this.
How to represent incoming/outgoing traffic?
As @mcollina asked, the Network panel in the browser's DevTools always represents client-side traffic. In Node.js, a server may both received and send requests, which has to be represented in the Network tab somehow.
Proposal: follow @nicoburns suggestion #75 (comment) and add both incoming/outgoing traffic in the Network. I'm not aware if CDP supports custom tags for network entries so we could have a checkbox to filter out different kinds of traffic.
How to record the traffic?
I appreciate different third-party suggestions (proxies/interception libraries) but I believe the most straightforward way to do that would be using
node:async_hooksand itsHTTPINCOMINGMESSAGEandHTTPOUTGOINGMESSAGEevents.What's to be done?
I have very little knowledge in the CDP but it looks like this is a rough roadmap:
async_hookslisteners (such as invoking.requestWillBeSent()for an requests and.responseReceived()for responses).Questions
async_hooksprovide sufficient data to be fed to the Network domain of the devtools? Is there any data that's missing/won't be observable?async_hooksas well? Otherwise it won't be observable.Socket, I assume. It's observable inasync_hooks, as far as I recall. Does that sound like a reliable strategy for implementing WebSocket support in the Network inspector?mcollina commentedon Dec 17, 2023
tbh I would instrument everything with diagnostic_channel and scoop data from there
starball5 commentedon Jan 16, 2024
Related on Stack Overflow:
github-actions commentedon Apr 16, 2024
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.
starball5 commentedon Apr 16, 2024
I would not like this issue to be closed. To that end, I bump.
GrinZero commentedon Jun 5, 2024
Expect to be able to listen to requests with chrome devtools made by your own program? You can refer to my recently developed open source library: https://github.com/GrinZero/node-network-devtools.
It edit the 'http' and 'https' module from your node program and use CDP to show the info in chrome devtools.
I also hope that the official can support it. It's exhausting to do this myself.
cola119 commentedon Jun 26, 2024
I hope nodejs/node#53593 can be a starting point to discuss how we can realize network inspection. If you have any suggestions, please feel free to share them!
mcollina commentedon Jul 1, 2024
Thank you @cola119!
legendecas commentedon Nov 4, 2025
The feature is now available with an experimental flag
--experimental-network-inspection. Closing and track the experiment status in nodejs/node#53946.quantuminformation commentedon Nov 4, 2025
cool