CSP error in Web Worker

Hi,

Iā€™m using a Web Worker in a Cloud Editor project. The worker is called and works fine.
Now Iā€™m trying to import an external module. But there seems to be something wrong with the content security policies:

Refused to load the script ā€˜https://cdn.jsdelivr.net/npm/inferencejs/+esmā€™ because it violates the following Content Security Policy directive: ā€œdefault-src noneā€. Note that ā€˜script-src-elemā€™ was not explicitly set, so ā€˜default-srcā€™ is used as a fallback.

My worker.js file:

let inferEngine = null;

onmessage = async function (e) {
  const { pixels, width, height } = e.data;
  console.log(width, height);

  if (!inferEngine) {
    const { InferenceEngine } = await import(
      "https://cdn.jsdelivr.net/npm/inferencejs/+esm"
    );

...

Is there another solution or am I doing something wrong?

If you were to try it not in module form do you still get the same error?

Example:

const inf = document.createElement('script')
inf.src = 'https://cdn.jsdelivr.net/npm/inferencejs/dist/inference.min.js'
inf.crossOrigin = 'anonymous'

inf.addEventListener('load', () => {
  console.log('loaded')
})

document.head.appendChild(inf)

I can load the script in 8th Wall, thatā€™s not an issue. But I want to do it async in a web worker. The worker is giving the CSP error

Can you share your project with the support workspace so i can take a look? We might have to do a workaround like making your Web Worker script into an asset bundle.

Done, I added the worker.js as an asset bundle.

Just took a look at your project! is there a reason youā€™re importing the library every time the onmessage function gets called on the Worker? I imagine it might be beneficial to load the library once in the head of the page and then use the worker to do the inference based off of the Inference Engine instance on the window.

Itā€™s only once right? Itā€™s checking if the engine has been loaded? But I donā€™t think this is causing the CSP error? Nevertheless I would expect it to work? Maybe not as optimal.

Just doing a little rubber duck debugging to better understand and potentially solve the issue. :slight_smile:

So youā€™re creating a web worker when the AR engine loads, and you want to offload the inference work to the worker and then use those results in a CameraPipelineModule?

Yes correct. Because if I do it on the main thread, you can notice some lag in the experience.