I am using the following javascript code to intercept ajax calls:
XMLHttpRequest.prototype.realOpen = XMLHttpRequest.prototype.open;
var newOpen = function(method, url, async, user, password) {
console.log("Intercepted open (" + url + ")");
this.realOpen(method, url, async, user, password);
}
XMLHttpRequest.prototype.open = newOpen;
The javascript which performs the ajax calls and the above code are loaded from:
https://example.com/js/main.js
https://example.com/js/intercept.js
The above code works well when the domain for ajax call is just "example.com", but when the ajax call is made for the domain "sub.example.com" the above code is not able to intercept that request.
Does anybody know why it would not work?