将 Chrome 扩展程序连接到 Firebase RTB 时出错:"firebase.database is not a function"



我正在尝试创建一个将一些信息保存到Firebase数据库的chrome扩展程序,但我无法让它工作。我已经遵循了快速入门.js示例和这篇文章,但我错过了一些东西。我有如下内容(这是简化的(:

manifest.json

{
"manifest_version": 2,
"name": "My extension",
"description": "saving info to firebase",
"version": "1.0",
"background": {
"scripts": [
"firebase-app.js",
"background.js"
],
"persistent": false
},
"browser_action": {
"default_popup": "popup.html"
},
[...]
"content_security_policy": "script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com; object-src 'self'; connect-src 'self' wss://*.firebaseio.com;"
}

应用.js

var config = {
apiKey: "XXX",
authDomain: "XXX.firebaseapp.com",
databaseURL: "https://XXX.firebaseio.com",
projectId: "XXX",
storageBucket: "XXX.appspot.com",
messagingSenderId: "XXX",
};
firebase.initializeApp(config);
var saveButton = document.getElementById('save');
function writeFirebase( A, B, C) {
var postData = {
first: A,
second: B,
third: C
};
var newPostKey = firebase.database().ref().child('info').push().key;
var updates = {};
updates['/info/' + newPostKey] = jobData;
return firebase.database().ref().update(updates);
}

saveButton.onclick = function() {
A = 'A';
B = 'B';
C = 'C';
writeFirebase(A, B, C);
};

应用.html

<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Tasty</title>
<link rel="stylesheet" href="css/app.css" />
</head>
<body>
<div>     
<button class="save" id="save">Save info</button>
</div>
<script src="https://www.gstatic.com/firebasejs/7.14.4/firebase-app.js"></script>
<script src="app.js"></script>
</body>
</html>

因此,当我单击保存按钮和应用程序时.js执行firebase.database((.ref((.child('info'(.push((.key; y 得到一个错误:

未捕获的类型错误:firebase.database 不是一个函数

有人可以帮助我吗? 谢谢!

根据文档,为了访问实时数据库,除了Firebase核心(firebase-app.js(之外,您必须包含数据库脚本,如下所示:

<script src="https://www.gstatic.com/firebasejs/7.14.6/firebase-database.js"></script>

相关内容

  • 没有找到相关文章

最新更新