Chron's avatar

Is there a way to use web worker that is not in public?

I'm using Laravel v12, Vue3, inertiajs, Vite, Sail.

I tried importing;

import myWorker from "@/workers/worker?worker";

const testingFunc = () => {
	const worker = new myWorker();
}

Where @ is resources/js/ but Firefox spits this message out:

Security Error: Content at http://localhost/testing-worker may not load data from http://[::1]:5174/resources/js/workers/worker.js?worker_file&type=module.

I also tried it on chromium's:

Uncaught SecurityError: Failed to construct 'Worker': Script at 'http://[::1]:5174/resources/js/workers/worker.js?worker_file&type=module' cannot be accessed from origin 'http://localhost'.

Putting the worker in /public folder makes it work, but is there a way to put it in /resources/js?

0 likes
0 replies

Please or to participate in this conversation.