Javascript and Firebase Error “This operation is not supported in the environment this application is running on. ”location.protocol“”

 ̄綄美尐妖づ 提交于 2020-01-07 04:38:25

问题


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.

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>

回答1:


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.



来源:https://stackoverflow.com/questions/45059919/javascript-and-firebase-error-this-operation-is-not-supported-in-the-environmen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!