I ran into an interesting problem while creating a hosted API that relies on web workers. I was hoping to get a little community feedback on it.
My server is set up with the appropriate CORS headers to deliver the worker JS files and can be retrieved with an XMLHttpRequest
object. However, when the URL is given to new Worker()
it fails to build, citing the origin being the problem. This seems to be an issue on both Firefox and Chrome. Check it out for yourself, and my workaround, here: http://jsfiddle.net/5ag42hb1/11/
Is this not odd behaviour? Mozilla docs say that Web Workers must obey same-origin policy and to use CORS to allow cross-origin access.
The fiddle has a workaround of storing the file in a blob and passing that to the worker instead. It seems less than ideal though, introducing a lot of unnecessary complexity. Can anyone think of a cleaner solution? Is there a good channel to get this implemented properly?