6
6
6367822020-01-21 05:47:05
JavaScript
636782, 2020-01-21 05:47:05

Websocket how to change incoming message?

Hello. I am writing a chrome extension. It is required to be embedded in websocket and modify incoming messages.
There are no problems with listening. You can listen through WebSocket.prototype.onMessage or by adding a listener to the message event:
WebSocket.addEventListener('message'...
The problem is that in both cases the text of the incoming message is readOnly. Are
there any ways to modify the incoming message?
I was thinking about making a local websocket proxy in browser, but as I understand it, in chrome it is impossible to raise
the websocket server?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arslan Isaev, 2020-01-21
@isaev_ars

https://learn.javascript.ru/websocket

R
rPman, 2020-01-21
@rPman

try replacing the method with your own, something like this:
https://stackoverflow.com/questions/40341197/how-t...

WebSocket.prototype.oldSend = WebSocket.prototype.send;

WebSocket.prototype.send = function(data) {
     console.log("ws: sending data");
     WebSocket.prototype.oldSend.apply(this, [data]);
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question