Is there any possibility to globally monitor all window.fetch
requests? I know it works with Promises, which is great, but I need to get notified whenever any of such requests is done (fail/success). I have no access to the functions which invoke these or are success/fail handlers.
So basically I'm looking for something like
window.addEventListener('fetch', ev => {
if (ev.type == 'FetchSuccess') {
// process ev.response
}
});
You can overwrite the fetch function the following way:
var oldFetch = fetch; // must be on the global scope
fetch = function(url, options) {
var promise = oldFetch(url, options);
// Do something with the promise
return promise;
}
This way you can get control over the returned promises while it maintains it's usage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With