the Fetch API is totally mutable and can be replaced or removed by doing
window.fetch = null;
or,
var fetch = null;
or, the fetch property can be removed as well.
delete window.fetch;
This means, if a legacy code defines a global variable named fetch, the fetch API cannot be used.
Is there any way to access the original fetch function in JavaScript?
I appreciate your answers but none of you answered the question properly. The fetch function is already erased and we have no way to access it. In this case we can use the following simple hack.
This will hand us the original fetch function.
function restoreFetch() {
if (!window._restoredFetch) {
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe); // add element
window._restoredFetch = iframe.contentWindow.fetch;
}
return window._restoredFetch;
}
Then, we can use the fetch API:
const f = restoreFetch();
const result = await f('https://stackoverflow.com');
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