Ask Your Question
4

Why is the construction of a new Worker() failing to be bundled by Webpack when using Angular, and displaying an error message referring to the unaccessible origin of the script file?

asked 2023-05-14 09:03:34 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-14 09:22:02 +0000

lakamha gravatar image

This is likely due to a security feature called "Same-Origin Policy" that prevents scripts loaded from one origin to access resources from a different origin. When using a Worker() constructor, the script file for the worker is loaded as a separate origin, which can cause issues when using Angular with Webpack.

To fix this issue, you can configure Webpack to bundle the worker script file as an inline blob, rather than a separate file. This can be done using the "worker-loader" plugin, which allows you to import a worker script file as a module and have it bundled by Webpack.

Alternatively, you can also host the worker script file on the same origin as the main script file, which will allow it to be loaded without triggering the Same-Origin Policy error.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-14 09:03:34 +0000

Seen: 9 times

Last updated: May 14 '23