Help us understand the problem. What is going on with this article?

Refused to create a worker from 'blobでコンテンツセキュリティポリシーで怒られた場合の対処法

More than 1 year has passed since last update.

Monacaでtessearact.jsを動かそうと思ったらコンソールに以下の画面が現れ、実行ができないエラーに遭遇してしまった。

Refused to create a worker from 'blob:file:///8c082fe9-ea7c-4bd6-8dbf-5ca6c339eb82'
because it violates the following Content Security Policy directive: 
"script-src * 'unsafe-inline' 'unsafe-eval'". 
Note that 'worker-src' was not explicitly set, so 'script-src' is used as a fallback.

どうやら、MonacaのプロジェクトテンプレートはデフォルトでXSSのような攻撃を抑止するためにHTTP headerにコンテンツセキュリティポリシーというものを設定しているらしいです。
以下、ご参考にさせて頂きました。
https://qiita.com/goofmint/items/0b60dcc5eccad6c794a2
https://content-security-policy.com/

エラーの内容から、blobと呼ばれるバイナリ形式のオブジェクトをセキュティで禁止しているようですので、許可を与えます。

index.html
<meta http-equiv="Content-Security-Policy" content="worker-src blob: ;default-src * data: gap: blob: content: https://ssl.gstatic.com; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">

デフォルトからworker-src blob: ;を追加し,default-srcblobを追加しています。

これで無事エラーは出なくなりました。

ただしこれはベストな方法ではないはずです。ベストな設定をご存知の方ご教授ください。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away