So I'm trying to modify the response text of a XHR request but only on a certain url. Heres what I have:
(function(http){
var get = Object.getOwnPropertyDescriptor(
http.prototype,
'responseText'
).get;
Object.defineProperty(
http.prototype,
"responseText",
{
get: function(){ return get.apply( this, arguments ) + '{"Admin":true}'}
}
);
})(self.XMLHttpRequest);
You can add parameters to XMLHttpRequest object:
var myUrl = 'https://www.google.es'
var xml = new XMLHttpRequest();
xml.onreadystatechange = function() {
if ( xml.readyState == 4) {
console.log(xml.url);
if(xml.url === 'https://www.google.es'){
//change response here
}
}
};
xml.open("GET", myUrl, true);
xml.url = myUrl;
xml.send();