Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to send a message to an existing websocket connection in Chrome?

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?

like image 246
Sergei Basharov Avatar asked Dec 10 '25 21:12

Sergei Basharov


1 Answers

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")
like image 82
egerardus Avatar answered Dec 12 '25 11:12

egerardus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!