简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM