首页 > 解决方案 > Firefox Addon 中的 Firebase:此应用程序运行的环境不支持此操作

问题描述

编辑:

我刚刚注意到我错误地发现了错误并且有一些错误:

运行此应用程序的环境不支持此操作。\"location.protocol\" 必须是 http、https 或 chrome-extension 并且必须启用网络存储

这是有道理的,因为我的页面的地址从moz-extension.

有什么解决方法吗?

原始问题:

我正在构建 Firefox 扩展。它会更改打开新标签后显示的默认页面。我想在该页面上使用 Firebase Auth。

在显示的 html 中,我创建了一个用于 Google 登录的按钮。单击它时,将执行以下代码:

var provider = new firebase.auth.GoogleAuthProvider();

$("#authenticated_user_content").hide();

$("#google_login").on("click", function() {
  console.log("GOogle login");
  firebase
    .auth()
    .signInWithPopup(provider)
    .then(function(result) {
      // This gives you a Google Access Token. You can use it to access the Google API.
      var token = result.credential.accessToken;
      // The signed-in user info.
      var user = result.user;
      // ...
      $("#not_logged_in_content").show();
      $("#authenticated_user_content").show();
    })
    .catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
      // The email of the user's account used.
      var email = error.email;
      // The firebase.auth.AuthCredential type that was used.
      var credential = error.credential;
      // ...
    });
});

发生的情况是:单击#google_login在浏览器控制台中显示“Google 登录”消息,但没有带有 Google 登录表单的弹出窗口。

Firefox 不会在控制台中显示任何错误(F12在浏览器中单击后)。我厌倦了去about:debugging点击Debug我的分机旁边。#google_login单击按钮后出现新窗口并显示此消息:

TypeError:无法访问死对象

还有其他方法可以调查问题所在吗?为什么弹窗不显示?Firefox 是否会阻止扩展程序显示的网页中的此类功能?

标签: firebasefirebase-authenticationfirefox-addon

解决方案


您需要创建 Google 提供程序对象的实例:

var provider = new firebase.auth.GoogleAuthProvider();

firebase
    .auth()
    .signInWithPopup(provider)

可选:指定要从身份验证提供程序请求的其他 OAuth 2.0 范围。要添加范围,请调用 addScope。例如:

provider.addScope('https://www.googleapis.com/auth/contacts.readonly');

请参阅身份验证提供程序文档。还有更多选择


推荐阅读