I am trying to intercept the HTTP call, made using the fetch
API. I read through:
and was trying the same thing, but I am not able to intercept the request made from the fetch
function.
Here is what I am doing:
(function(open) {
XMLHttpRequest.prototype.open = function() {
this.addEventListener("readystatechange", function() {
console.log(this.readyState);
}, false);
open.apply(this, arguments);
};
})(XMLHttpRequest.prototype.open);
fetch("http://jsonplaceholder.typicode.com/posts")
.then(response => {
console.log(response);
})
.catch(err => {
console.log(err);
})
I receive the response without interceptor being invoked. What is it that I am missing? I want to add an intercept to HTTP request no matter if the application were created using ReactJS, Angular or vanilla JS.