我在调用firebase的 signInWithEmailAndPassword 方法时遇到以下异常:
以下是我的content.js文件的代码:
var config = {
apiKey: "******",
authDomain: "******",
databaseURL: "******",
projectId: "******",
storageBucket: "******",
messagingSenderId: "******"
};
var firebase_email = "firebase_email"; var firebase_password = "firebase_password";
firebase.initializeApp(config);
firebase.auth().signInWithEmailAndPassword(firebase_email, firebase_password)
.then((result) => console.log('Signin result', result))
.catch(function (error) {
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === "auth/wrong-password") {
alert("Wrong password for Firebase API in config.");
} else {
console.log(errorMessage);
}
console.log(error);
});
以下是我的 manifest.json 文件的代码:
{
"manifest_version": 2,
"name": "Firebase Auth in Chrome Extension Sample",
"description": "This sample shows how to authorize Firebase in a Chrome extension using a Google account.",
"version": "0.1",
"content_scripts": [{
"matches": [
"https://some websitename*",
],
"js": ["jquery-3.2.1.min.js", "firebase.js", "content.js"]
}],
"browser_action": {
"default_icon": "icon.png",
"default_title": "My Extension!"
},
"permissions": [
"identity",
"https://*/*",
"activeTab",
"background",
"storage"
],
"content_security_policy":"script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com; object-src 'self'"
}
奇怪,当我将其作为JavaScript应用程序运行时,相同的代码也起作用,请参见以下屏幕截图:
我尝试了各种方法,但无法确定背后的原因。 请指引我正确的方向。
谢谢