Javascript和Firebase错误“此应用程序正在其上运行的环境中不支持此操作."location.protocol" [英] Javascript and Firebase Error "This operation is not supported in the environment this application is running on. "location.protocol""

查看:60
本文介绍了Javascript和Firebase错误“此应用程序正在其上运行的环境中不支持此操作."location.protocol"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过google auth通过Firebase登录编写纯Javascript Web应用程序,当我在javascript中设置auth时收到错误消息此应用程序运行的环境不支持此操作." location.protocol必须为http,https或chrome-extension,并且必须启用网络存储.".我不确定该怎么办.

I am trying to write a pure javascript web app with firebase login through google auth, when I setup the auth in javascript I get the error "This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled.". I am not sure what do to.

这是我的代码(我删除了ID和其他代码):

Here is my code (I removed my id's and whatnot):

<script src="https://www.gstatic.com/firebasejs/4.1.3/firebase.js"></script>
    <script>
        // Initialize Firebase
        var config = {
            apiKey: "MY KEY",
            authDomain: "MY DOMAIN",
            databaseURLMY URL",
            projectId: "MY ID",
            storageBucket: "MY BUCKET",
            messagingSenderId: "MY ID"
        };
        firebase.initializeApp(config);


        function login() {
            function newLoginHappened(user) {
                if (user) {
                    //User is signed in
                    app(user);
                } else {
                    var provider = new firebase.auth.GoogleAuthProvider();
                    firebase.auth().signInWithRedirect(provider);
                }
            }

            firebase.auth().onAuthStateChanged(newLoginHappened);
        }

        function app() {
            document.getElementById("clientName").innerHTML = user.displayName;
        }

        window.onload = login;
    </script>

推荐答案

这意味着您无法通过双击html并在浏览器中打开文件来运行文件.您需要通过服务器运行文件.

It means that you cannot run the file by just double clicking the html fine and opening it in browser. You need to run the file through a server.

这篇关于Javascript和Firebase错误“此应用程序正在其上运行的环境中不支持此操作."location.protocol"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆