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. 
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.