I use Network > WS
tab in Chrome to debug my websocket connections data. I wonder if it's possible to select an existing connection and send data to it without having to connect manually from console?
Asked
Active
Viewed 4,555 times
3

Sergei Basharov
- 51,276
- 73
- 200
- 335
-
Does this answer your question? [In Firefox/Chrome devtools Is there a way to send/edit websocket messages after connection](https://stackoverflow.com/questions/59242245/in-firefox-chrome-devtools-is-there-a-way-to-send-edit-websocket-messages-after) – Mišo Feb 16 '23 at 14:07
1 Answers
1
Unfortunately no, not currently.
Not sure what this means exactly:
without having to connect manually from console?
I am assuming this means you are creating the websocket in the Chrome console which would be tedious. You could scope the websocket in your code so you can access it from the console and then you would just have to type .send()
in the console when testing. For example:
// in your code
const url = new URL('/path/to/ws', window.location.href);
url.protocol = 'ws';
window.ws = new WebSocket(url.href);
Then you would only need to type this from the console for testing:
window.ws.send("this is a test msg")

egerardus
- 11,316
- 12
- 80
- 123