Last active
December 10, 2018 20:35
-
-
Save THEtheChad/4353b2ae5869fcac47b8e91abe057dbd to your computer and use it in GitHub Desktop.
Intercept XHR requests for tracking ajax events.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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