Skip to content

Design and sizing for WebSocket support #9507

Closed

Description

@srawlins

When an app makes WebSocket requests via dart:io's WebSocket class, the requests appear in the Network Screen as opaque 'SOCKET' requests. Users have requested first-class WebSocket support, much like the existing HTTP support (#8223).

This would be a sizable effort. The goal of this issue is to flesh out the work a bit, and size it.

HTTP support

How was support implemented for HTTP requests?

  1. Scaffolding was added to dart:io and the VM service to support profiling, including an _HttpProfile class. dart-lang/sdk@558875d
  2. Hooks were added to dart:io to allow HttpClient.enableTimelineLogging to be set remotely. dart-lang/sdk@93c9eba
  3. In dart:io and the VM service, a httpEnableTimelineLogging service extension was added. dart-lang/sdk@e85e5b6
  4. In dart:io and the VM service, HTTP network profiling services were added. dart-lang/sdk@c4bfca9
  5. Added APIs to dart:developer to record and retrieve HTTP profile info. dart-lang/sdk@628d744
  6. A skeleton http_profile package was added: dart-lang/http@04777ac
  7. The http_profile package was fleshed out: dart-lang/http@ce0de37
  8. More API in the http_profile package. dart-lang/http@5dfea72, dart-lang/http@9f47439
  9. Integrate cupertino_http with the http_profile package. dart-lang/http@46d49e3
  10. Integrate cronet_http with the http_profile package. dart-lang/http@4726f43

What will be required for WebSocket requests?

In very broad strokes, the support required for HTTP requests included (1) support in dart:io's HttpClient, (2) support in the VM service, (3) support in dart:developer, (4) shared types in a new http_profile package, (5) integration in several other HTTP-related packages, (6) support in DevTools. At a glance, it looks like we need to make similar changes to each of these 6 areas in order to support WebSocket requests. Can it be reduced? For example, do we need a new web_socket_profile package, or can we piggy-back off of the http_profile package?

@bkonyi You allude to this question here. I think we would want to make the support generic, and add to the http_profile package. This is primarily because there has been much recent movement in this space a la @brianquinlan 's work:

WebSocket plan

  1. Update HttpClient.enableTimelineLogging to also start recording WebSocket details. This involves dart:developer, dart:io.
  2. Add support for sending this recorded data in the VM service extensions.
  3. Add support in the http_profile package.
  4. Integrate with cupertino_http package, web_socket package (maybe web_socket_channel package?).
  5. Add support to DevTools.

Activity

  1. added
    P2important to work on, but not at the top of the work list.
    on Nov 5, 2025
  2. Victowolf commented on Feb 21, 2026

    @Victowolf
    Contributor

    Hi @srawlins,

    I’m Yash (VictoWolf) ,

    Continuing the discussion from #9670,

    I started with retracing the http support to understand how it was implemented, by following the above explanation given in this issue.
    I was able to create a flow:

    HttpClient()     " sdk/lib/io/  "
        ↓
    _http_impl.dart      " sdk/lib/_http/http_impl.dart "
        ↓
    _HttpProfileData   " sdk/lib/_http/http_impl.dart "
        ↓
    network_profiling.dart        " sdk/lib/io/network_profiling.dart "
        ↓
    ext.dart.io.getHttpProfile    " sdk/lib/io/network_profiling.dart "
        ↓
    VM Service JSON     " sdk/runtime/vm/ "
        ↓
    DevTools network_service.dart  " packages/devtools_app/lib/src/screens/network/network_service.dart " : flutter/DevTools 
        ↓
    network_model.dart    " packages/devtools_app/lib/src/screens/network/network_model.dart " : flutter/DevTools 
        ↓
    Network UI   " packages/devtools_app/lib/src/screens/network/network_screen.dart " : flutter/DevTools 
    

    I also mapped them to folders/file where they are implemented.


    Now for implementing WebSocket, i first noted down what all is already implemented for WebSockets.
    what i found was:

    • websocket.dart " sdk/lib/_http/ "
    • websocket_impl.dart " sdk/lib/_http/ "

    They currently handle handshakes, Frame encoding/decoding, Ping/pong & Close frames.
    But there is no profiling instrumentation like _HttpProfileData, no VM extension like: ext.dart.io.getWebSocketProfile
    This makes WebSocket traffic not surfaced in DevTools with protocol semantics (e.g., lifecycle or frame-level visibility).


    To accommodate WebSocket we can probably

    • Extend the current profiling which is for Http to represent connection-oriented protocols.
    • Record WebSocket lifecycle events (connect, message/frame send/receive, close) using a generalized profiling structure.
    • Augmenting it to the existing network profiling service extension instead of introducing a separate one.
    • Updating DevTools’ network model to handle both request-based (HTTP) and connection-based (WebSocket).

    The above plan follows for:

    I think we would want to make the support generic, and add to the http_profile package.


    For gRPC, as included in the GSOC project list, Still have to learn about it. 😅


    So, To proceed further with Sample project i wanted to clarify whether my above understanding is in right direction...?

    Thanks....

  3. Victowolf commented on Feb 23, 2026

    @Victowolf
    Contributor

    Hi @elliette,

    After the recent update to the project list.

    I was creating plan for building the Sample project.
    I came across 2 approaches:


    Approach 1
    Create a simple ProfileableWebSocket wrapper that intercepts add() for outgoing messages and uses listen() for incoming messages.

    Approach 2
    Use a StreamTransformer to compose incoming logging via a transformed stream (e.g., customStream.listen()), and still intercept add() separately for outgoing messages.

    The 2nd approach gives more composable incoming from a Stream perspective. but have to implement add() for outgoing.
    For the prototype, I am thinking to go with approach 1, so i need some guidance here .


    I also wanted to add some extra features to the prototype, these are:

    • Lifecycle style hooking which will give more debugging info

      • After WebSocket.connect() → handshake complete
      • Inside add() → message sent
      • Inside listen() → message received
      • Inside onDone → close event
      • Inside onError → error event
        My goal is to demonstrate lifecycle capture without modifying SDK internals.
    • Connection Based Loging which will give a complete summary like

      • Duration: Total Time duration
      • Messages Sent: Total Outgoings
      • Messages Received: Total Incomings
      • Total Bytes Sent: Total outgoing size
      • Total Bytes Received: Total Incoming Size

    For the sample project would you prefer the above additions ?

    Thanks,

  4. elliette commented on Feb 23, 2026

    @elliette
    Member

    Hi @Victowolf - this issue isn't being actively monitored, so for questions the best place to ask is https://groups.google.com/g/dart-gsoc.

    For your first question, please see this thread

    For your second question, you are welcome to add extra functionality to the starter project, those both sound like useful metrics to capture.

    Hope that helps! Please direct further questions to https://groups.google.com/g/dart-gsoc. Thanks!

  5. Victowolf commented on Feb 24, 2026

    @Victowolf
    Contributor

    ok sure,
    That helps a lot..
    Thanks.

  6. abdullah-arain9 commented on Mar 30, 2026

    @abdullah-arain9

    Hi Samuel,

    I am Abdullah Arain, a GSoC 2026 applicant
    for this project. I have studied this issue
    thoroughly along with all the HTTP profiling
    commits you referenced above.

    Based on your HTTP profiling implementation
    path, I built a working prototype that
    demonstrates the WebSocket instrumentation
    approach:

    github.com/abdullah-arain9/websocket-devtools-profiler

    Key achievements:

    • ProfileableWebSocket implements the full
      dart:io WebSocket interface as a drop-in
      replacement
    • Events posted via dart:developer
      Timeline.instantSync() — same mechanism
      as HTTP profiling today
    • 9 unit tests passing with MockWebSocket
      — no network required
    • Working CLI demo connected to real echo server

    My proposal follows your suggested plan exactly:

    1. Update HttpClient.enableTimelineLogging
      for WebSocket
    2. VM Service extension support
    3. http_profile package integration
    4. DevTools Network Panel WebSocket tab

    GSoC 2026 proposal submitted. Would love
    any feedback before the deadline!

    — Abdullah Arain
    github.com/abdullah-arain9

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

    P2important to work on, but not at the top of the work list.devtools-network-screenIssues with the Network screen.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions