gpt4 book ai didi

javascript - 在 JS 中将 Firebase 添加到 Chrome 扩展时出错

转载 作者:行者123 更新时间:2023-12-02 23:52:58 24 4
gpt4 key购买 nike

我在 JS 中使用 Firebase 时遇到问题,特别是在扩展上。

这是我的 Manifest.json

{
"manifest_version": 2, //required
"version": "1.0", //required
"name": "Hello World!", //required
"description": "Learning how to make a chrome extension!",
"icons": {
"16": "images/puppy16.png",
"48": "images/puppy48.png",
"128": "images/puppy.png"
},
"browser_action":
{
"default_icon": "images/puppy.png",
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"]
},
"content_security_policy": "script-src 'self' https://cdn.firebase.com https://*.firebaseio.com; object-src 'self'"
"permissions": [
"identity",
"tabs",
"activeTab",
"http://*/*",
"https://*/*"
]
}

这是我的background.js 文件

 // Initialize Firebase
var config = {
apiKey: "xxxxxx",
authDomain: "xxx.firebaseapp.com",
databaseURL: "xxxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx"
};
firebase.initializeApp(config);

var rootRef = firebase.database().ref();

function writeUserData(userId, name, email, imageUrl) {
rootRef.database().ref('users/' + userId).set({
username: name,
email: email,
profile_picture : imageUrl
});
}
writeUserData("11", "pete", "p@g.com", "google.com")

我特别收到一条错误,指出:Uncaught ReferenceError:firebase 未定义。

也许问题出在外部库中?

最佳答案

您尚未以任何方式导入 firebase SDK。仅将它们放在同一个文件夹中不足以让您的文件了解 firebase。将 firebase SDK js 文件添加到 list 的脚本部分,位于 background.js 脚本之前。假设它名为 firebase.js,您的 list 中应包含以下行:

"scripts": ["firebase.js", "background.js"]

关于javascript - 在 JS 中将 Firebase 添加到 Chrome 扩展时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55559738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com