Tuesday, 7 December 2021

Intercept websocket messages

With ajax requests it can be done with this code:

  let oldXHROpen = window.XMLHttpRequest.prototype.open;
  window.lastXhr = '';
  window.XMLHttpRequest.prototype.open = function(method, url, async, user, password){
    this.addEventListener('load', function(){
      window.lastXhr = this.responseText;
    });       
    return oldXHROpen.apply(this, arguments);
  };

lastXhr variable will hold the last response.

But how can this be achieved for websockets too ?



from Intercept websocket messages

No comments:

Post a Comment