繁体   English   中英

在JS中将Firebase添加到Chrome扩展程序时出错

[英]Error when adding Firebase to Chrome extension in JS

我无法让Firebase在JS中工作,特别是在扩展上工作。

这是我的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") 

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

也许问题出在外部库中?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM