如何将 google chrome 扩展程序与我的 firebase 数据库 链接起来。 我试过像连接一个简单的网页一样连接它,但它不能与扩展一起使用。当我在我的 html 文件中初始化 firebase 时,它给出了关于内联代码的错误。错误如下:Refused to load the script 'cdn.firebase.com/v0/firebase.js';因为它违反了以下内容安全策略指令:“script-src 'self' blob: filesystem: chrome-extension-resource:”
// Initialize Firebase
Firebase.enableLogging(true);
var ref = new Firebase("https://test-7c659.firebaseio.com")
var config = {
apiKey: "AIzaSyBxmZNZ0FyHavvPQ7Q7fQAn2875qmdXtH0",
authDomain: "test-7c659.firebaseapp.com",
databaseURL: "https://test-7c659.firebaseio.com",
projectId: "test-7c659",
storageBucket: "test-7c659.appspot.com",
messagingSenderId: "578149428062"
};
firebase.initializeApp(config);
<!doctype html>
<!--
This page is shown when the extension button is clicked, because the
"browser_action" field in manifest.json contains the "default_popup" key with
value "popup.html".
-->
<html>
<head>
<script src="canvasjs.min.js"></script>
<script src="popup.js"></script>
<link rel="stylesheet" type="text/css" href="bootstrap.css">
<title>Neurostic</title>
<style>
body {
margin: 20px 20px 8px 20px;
width: 400px;
direction: ltr;
height: 400px;
}
</style>
</head>
<body>
<h4 id = "object" onclick="fire();">Health Care</h4>
<div id="chartContainer" style="height: 300px; width: 100%;" ></div>
<script type="text/javascript" src="https://cdn.firebase.com/v0/firebase.js"></script>
<script type="text/javascript" src=add_firebase()></script>
</body>
</html>
最佳答案
确保您添加的是正确的 content-security-policy
在您的 chrome 扩展程序的 list 文件中。
您应该将以下内容添加到您的 manifest.json 文件中:
"content_security_policy":"script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com; object-src 'self'"
您可以使用以下方法将 firebase.js 包含在您的扩展程序的 html 中:
<script src="https://www.gstatic.com/firebasejs/4.0.0/firebase.js"></script>
请注意,根据您阅读此答案的时间,firebasejs 的版本可能会发生变化。通过检查 here 包含最新版本.
此外,您还可以找到在 chrome 扩展程序中使用 firebase 的示例 here
关于javascript - chrome 扩展无法将其与我的 firebase 数据库链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43497733/