Skip to content

Instantly share code, notes, and snippets.

@THEtheChad
Last active December 10, 2018 20:35
Show Gist options
  • Save THEtheChad/4353b2ae5869fcac47b8e91abe057dbd to your computer and use it in GitHub Desktop.
Save THEtheChad/4353b2ae5869fcac47b8e91abe057dbd to your computer and use it in GitHub Desktop.
Intercept XHR requests for tracking ajax events.
(function(open){
var targetURL = new RegExp('http://google.com');
XMLHttpRequest.prototype.open = function(){
this.addEventListener('readystatechange', function(){
if(this.readyState !== 4) return;
if(this.status < 200 || this.status >= 300) return;
if(!targetURL.test(this.responseURL)) return;
// SUCCESS
// code to execute here
}, false);
open.apply(this, arguments);
}
})(XMLHttpRequest.prototype.open)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment