小编foh*_*ohx的帖子

如何在Chrome Extension Manifest.json中设置内容安全策略以使Firebase正常工作

我做了一个Chrome扩展程序,并使用Firebase将数据收集到了数据库中。一段时间以来,它的工作情况还不错,但是Chrome似乎有所更改。现在,在扩展程序上使用Inspect Element时,在JavaScript控制台中出现以下错误:

拒绝加载脚本' https://(myID).firebaseio.com /(otherprivatedata) ',因为它违反了以下内容安全策略指令:“ script- src'self'chrome -extension-resource:”。

该脚本写在firebase.js:171上,它不是我添加的脚本。

我试图按照此指南进行操作,并按照指示将“ content_security_policy”标签添加到manifest.json中:https : //github.com/firebase/firebase-chrome-extension

我按照指示将以下行添加到manifest.json中:

"content_security_policy": "script-src 'self' https://cdn.firebase.com https://*.firebaseio.com; object-src 'self'"
Run Code Online (Sandbox Code Playgroud)

但是,当我添加此行时,现在尝试在chrome:// extensions中加载脚本时出现错误

加载扩展程序时出错

无法从以下位置加载扩展名:〜\ XXX \ my_ext

清单无效的JSON。行:14,列:5,语法错误。

它突出显示了我刚刚在上面添加的那一行(content_security_policy)。我究竟做错了什么?Chrome完全拒绝了“ content_security_policy”之后的所有内容。

即使我尝试使用Google的示例代码,也无法正常工作。developer.chrome.com/extensions/contentSecurityPolicy

"content_security_policy": "script-src 'self' https://example.com; object-src 'self'"
Run Code Online (Sandbox Code Playgroud)

如何设置content_security_policy以便Firebase在Extension中工作?

(我的firebase.jp已下载并与扩展程序打包在一起,因为Chrome不允许我将其称为远程。)

javascript json google-chrome google-chrome-extension firebase

3
推荐指数
1
解决办法
1万
查看次数