CORS from Webworker?

Actually it works using the direct URL but here I'm preloading a bunch of videos in a WebWorker:
const preloadVideo = async (url: string) => {
const res = await fetch(url)
const blob = await res.blob()
return URL.createObjectURL(blob)
}

onmessage = async ({ data }: MessageEvent) => {
for (const videoUrl of data.videos) {
const url = await preloadVideo(videoUrl)
preloadedMedia.videos.push(url)
postMessage(preloadedMedia)
}
})
const preloadVideo = async (url: string) => {
const res = await fetch(url)
const blob = await res.blob()
return URL.createObjectURL(blob)
}

onmessage = async ({ data }: MessageEvent) => {
for (const videoUrl of data.videos) {
const url = await preloadVideo(videoUrl)
preloadedMedia.videos.push(url)
postMessage(preloadedMedia)
}
})
so there is a .fetch() involved
5 Replies
Sid
Sid•3y ago
Interesting, the same request outside a webworker works?
flayks
flayksOP•3y ago
I'd believe so, I'm not totally certain so far, trying to investigate if it's my implementation or CORS issues from R2
Sid
Sid•3y ago
Yeah if it works outside the WebWorker then I'd assume your CORS policy is correct (unless there's something the browser does to mess with things, but that is unlikely)
flayks
flayksOP•3y ago
I just think I'm tired, or silly (or both tbh 😂)
<source type="video/{source.format}" src={source.url}>
<source type="video/{source.format}" src={source.url}>
Knowing that source.format value is video/mp4… it gives video/video/mp4… 🤦 just some leftover of refactoring actually. But I definitely did forget to add the CORS at the first place!
Sid
Sid•3y ago
Oh haha glad this is sorted then!

Did you find this page helpful?