Open Bug 1618711 Opened 5 years ago Updated 1 year ago

Author and send a new WebSocket message

Categories

(DevTools :: Netmonitor, enhancement, P3)

enhancement

Tracking

(Not tracked)

People

(Reporter: Harald, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-needed, Whiteboard: good-first-bug)

Option 1: Exposed as secondary toolbar:

                                                   (Toggles 2nd toolbar)
                                                           ↓
1st toolbar:           [🗑] [All ▼] [  Filter Messages  ] [➕]
Optional 2nd toolbar:  [      Plain Message Text     ] [Send]

Option 2: Add form below messages table (where the message will appear). Skip the Send button and use enter-to-send (Console-style).

Prior art:

https://chrome.google.com/webstore/detail/simple-websocket-client/pfdhoblngboilpfeibdedpjgfnlcodoo?hl=en

Honza: I assume this needs some backend work. Is this a good first bug or rather a small-scope enhancement for the 20% backlog?

Flags: needinfo?(odvarko)

I think that I can provide enough instructions (for DevTools part) to make this good first bug but, we are missing API on the platform.

The WebSocket Inspector is based on nsIWebSocketEventService and nsIWebSocketEventListener but, I don't see any way to send a frame (from within the DevTools UI).

https://searchfox.org/mozilla-central/rev/b2ccce862ef38d0d150fcac2b597f7f20091a0c7/netwerk/protocol/websocket/nsIWebSocketEventService.idl#40

What we need is API that would allow us to specify an existing WS connection using its ID and a payload to send. Something as follows:

nsIWebSocketEventService.send(aWebSocketSerialID, payload);

Where aWebSocketSerialID is the ID we get from the platform in nsIWebSocketEventListener callbacks and payload can be a string, blob or array buffer I guess.

Baku, we are thinking about this new feature - allowing the user to send WS frames from within the DevTools UI.
It would be great to know the scope of the platform work before we put this on anybody's roadmap.
What do you think how complex it would be to implement such API?

Honza

Flags: needinfo?(odvarko) → needinfo?(amarchesini)

This is relatively simple to do with nsIWebSocketEventListener if this listener runs on the same process as the webSocket object.
If this is the case, here is what we can do:

  1. each WebSocketImpl can be registered as weak-ref into WebSocketEventSource
  2. we implement nsIWebSocketEventService.send(aWebSocketSerialID, payload)
  3. the payload is received by the webSocketImpl and sent through the network on the correct thread.

In theory, the payload can be a string, an arrayBuffer/view or a Blob. How can support all these types from the UI?

I don't have time to work on this, but I can review code and/or mentor somebody.

Flags: needinfo?(amarchesini)

In theory, the payload can be a string, an arrayBuffer/view or a Blob. How can support all these types from the UI?

MVP should just be string support.

This is relatively simple to do with nsIWebSocketEventListener if this listener runs on the same process as the webSocket object.

Is this assumption correct?

Flags: needinfo?(odvarko)

So, we handle WS messages here:
https://searchfox.org/mozilla-central/rev/c79c0d65a183d9d38676855f455a5c6a7f7dadd3/devtools/server/actors/network-monitor/websocket-actor.js#100

And this code is running on the content process.

Andrea, I assume the webSocket object is also running on the content process, correct?

Honza

Flags: needinfo?(odvarko) → needinfo?(amarchesini)

Andrea, I assume the webSocket object is also running on the content process, correct?

This is correct.

Flags: needinfo?(amarchesini)

The backend stuff is done and UX pointers available.
Marking as good first bug.

Honza

Whiteboard: good-first-bug
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.