Skip to content

Web worker not working if base path is not on root / #17258

Discussion options

You must be logged in to vote

So the solution was to use full url for the file.

new SharedWorker(new URL(window.location.origin + window.location.pathname + 'src/foo/bar/baz/worker.js'));

This is a must if the app is not residing on root path/url / but rather in a sub-directory. But it also works if it does.

PS: If you need to import a dependency into the worker, the import must be done as a module:

new SharedWorker(new URL(window.location.origin + window.location.pathname + 'src/foo/bar/baz/worker.js'), {type: "module"});

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ivanjaros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant