Skip to content

Refused to create a worker because it violates the following Content Security Policy directive: worker-src #1715

Answered by kettanaito
cmacdonnacha asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @cmacdonnacha.

Why is this happening?

It looks like your server has a strict Content-Security-Policy defined that only allows certain origins for worker-src. To my best knowledge, worker-src blob: translates to: only allow installing workers at the blob: identifier. Since MSW worker is installed using the http: scheme, it violates the set security policy, raising the error you see.

How to resolve it?

First, see if you can adjust the Content-Security-Policy values on your server. Those make sense in production but you may have a looser set for development to allow tools like MSW.

If you don't own the server or cannot adjust the said policy, you can look into browser-level whitelisting …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@cmacdonnacha
Comment options

Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants