Why does fetch()
work on Data URIs?
A while ago, when I was learning how to use XMLHttpRequest
and fetch
, I saw absolutely no documentation that stated these methods could be used on anything but HTTP requests. I have tried this on both Firefox and Chrome and yielded the same result. Try for yourself.
(async function() {
let dataURI = 'data:text/plain,' + encodeURIComponent('Why does this work?'),
fetchResponse = await fetch(dataURI),
fetchBlob = await fetchResponse.blob();
console.log(URL.createObjectURL(fetchBlob));
})()
This below ends up simplifying Data URI to blob conversion rather than doing something like this question:
await(await fetch('data:text/plain,42').blob()