I’m using a npm package which internally create web workers. I need to send the base URL to the library config, and it uses that URL to fetch the worker files. In our case, it’s a CDN path.
As it’s a different origin from the hosted application, the worker creation is failing with the following error.
Uncaught DOMException: Failed to construct ‘Worker’: Script at
‘cdn.com/worker.js’ cannot be accessed from origin ‘example.com’
I already saw some solutions which suggest to reference a Blob URL while creating a worker.
Something like this: new Worker(blobUrl);
As the worker creation is within the dependency library, we can’t change the way the worker is being initialised. I wanted to know if there’s a way to make it work with a different origin.
Does anyone already recognise this problem?
Thanks!