Skip to content

Instantly share code, notes, and snippets.

@cppio
Created April 19, 2019 18:19
Show Gist options
  • Select an option

  • Save cppio/8003ebc505fedf2dc41830df76bba42e to your computer and use it in GitHub Desktop.

Select an option

Save cppio/8003ebc505fedf2dc41830df76bba42e to your computer and use it in GitHub Desktop.
Log WebSocket calls
((prototype, CONNECTING, OPEN, CLOSING, CLOSED) => {
WebSocket = function() {
const ws = new prototype.constructor(...arguments);
console.trace("new WebSocket", arguments, "=>", ws);
ws.addEventListener("message", event => console.log(event.data));
return ws;
};
WebSocket.prototype = prototype;
WebSocket.CONNECTING = CONNECTING;
WebSocket.OPEN = OPEN;
WebSocket.CLOSING = CLOSING;
WebSocket.CLOSED = CLOSED;
})(WebSocket.prototype, WebSocket.CONNECTING, WebSocket.OPEN, WebSocket.CLOSING, WebSocket.CLOSED);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment