I'm new to Javascript and am trying to write a userscript which tracks all Ajax calls made within a specific website and if the reponse status code is not 200, I want to automatically repeat that request. Also these requests I want to repeat are all POST requests which probably makes it even harder.
I've come so far that I'm tracking all Ajax calls but since it seems to be impossible to capture the formdata sent from the POST requests, I don't know how I could repeat the failed calls.
(function() { // Overriding XMLHttpRequest
var oldXHR = window.XMLHttpRequest;
function newXHR() {
var realXHR = new oldXHR();
realXHR.addEventListener("readystatechange", function() {
console.log("an ajax request was made")
console.log(realXHR.status)
//If the status is not 200, repeat the request with same data etc
}, false);
return realXHR;
}
window.XMLHttpRequest = newXHR;
})();