Skip to content

Support Network Inspection #75

Closed
Closed

Description

@eugeneo

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.

Activity

  1. sidorares commented on Dec 1, 2016

    @sidorares

    would be great to have support for node tcp/udp as well, not sure if that can fit into existing UI and debugger protocol

  2. hybrist commented on Dec 1, 2016

    @hybrist
    Contributor

    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.

  3. eugeneo commented on Dec 1, 2016

    @eugeneo
    Author

    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.

  4. hybrist commented on Dec 2, 2016

    @hybrist
    Contributor

    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.

  5. matthewloring commented on Dec 2, 2016

    @matthewloring

    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.

  6. alnorris commented on Feb 24, 2017

    @alnorris

    Would it be possible to monkey patch this? Similar to how node inspector does it?

  7. paulirish commented on Feb 26, 2017

    @paulirish
    Contributor

    @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

  8. joshgav commented on Feb 27, 2017

    @joshgav
    Contributor

    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.

  9. joshgav commented on May 11, 2017

    @joshgav
    Contributor

    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.

  10. changed the title [-]Support for HTTP/WS inspection[/-] [+]Support Network Inspection[/+] on May 11, 2017
  11. joshgav commented on May 11, 2017

    @joshgav
    Contributor

    @eugeneo I changed the title so it would be more obvious what this issue is about, please change back if you disagree. Thanks!

  12. eugeneo commented on May 11, 2017

    @eugeneo
    Author

    @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.

  13. hybrist commented on Oct 24, 2017

    @hybrist
    Contributor

    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):

    void InspectorSession::DispatchProtocolMessage(const String& method,
                                                   const String& message) {
      DCHECK(!disposed_);
      if (v8_inspector::V8InspectorSession::canDispatchMethod(
              ToV8InspectorStringView(method))) {
        v8_session_->dispatchProtocolMessage(ToV8InspectorStringView(message));
      } else {
        inspector_backend_dispatcher_->dispatch(
            protocol::StringUtil::parseJSON(message));
      }
    }
    

    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.

  14. eugeneo commented on Oct 24, 2017

    @eugeneo
    Author

    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.

  15. eugeneo commented on Oct 24, 2017

    @eugeneo
    Author

    @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.

  16. 47 remaining items

  17. quantuminformation commented on Sep 11, 2023

    @quantuminformation
  18. kettanaito commented on Dec 14, 2023

    @kettanaito

    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_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:

    1. Node.js has to implement the Network domain of the CDP.
    2. 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).
    3. Node.js has to differentiate between the outgoing and incoming requests somehow.
    4. Tests.

    Questions

    1. @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?
    2. I suppose with the WebSocket API landing natively in Node.js it will support async_hooks as well? Otherwise it won't be observable.
    3. 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?
  19. mcollina commented on Dec 17, 2023

    @mcollina
    SponsorMember
    1. yes
    2. if not it can be added
    3. 3rd party would not be supported (or possibly)

    tbh I would instrument everything with diagnostic_channel and scoop data from there

  20. github-actions commented on Apr 16, 2024

    @github-actions

    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.

  21. starball5 commented on Apr 16, 2024

    @starball5

    I would not like this issue to be closed. To that end, I bump.

  22. GrinZero commented on Jun 5, 2024

    @GrinZero

    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.

  23. cola119 commented on Jun 26, 2024

    @cola119
    Member

    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!

  24. mcollina commented on Jul 1, 2024

    @mcollina
    SponsorMember

    Thank you @cola119!

  25. legendecas commented on Nov 4, 2025

    @legendecas
    Member

    The feature is now available with an experimental flag --experimental-network-inspection. Closing and track the experiment status in nodejs/node#53946.

  26. quantuminformation commented on Nov 4, 2025

    @quantuminformation

    cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions