How To Override WebSocket Send() Method
I'm trying to override the WebSocket.send() method. My objective is being able to fuzz the sent data to test robustness of the server implementation. I'm adopting this approach: //
Solution 1:
How about:
WebSocket.prototype.oldSend = WebSocket.prototype.send;
WebSocket.prototype.send = function(data) {
console.log("ws: sending data");
WebSocket.prototype.oldSend.apply(this, [data]);
};
Solution 2:
As far as I know, you can't override WebSocket.send() implementation, as it is read-only in most of browser.
All you can do is something like:
var mysend = function(data) {
console.log("ws: sending data");
WebSocket.send(data);
};
which should do the trick anyway, without messing with prototypes.
Post a Comment for "How To Override WebSocket Send() Method"