Javascript Web Firebase get token running local but not running in public IP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm new in Firebase, and I am trying to figure out how to make my simple web app get token.



Since this is just prototype, I have 3 files.



1: init.js



// Initialize Firebase
const config = {
apiKey: "XXXXX",
authDomain: "XXXXX",
databaseURL: "XXXXXXX",
projectId: "XXXXXXXX",
storageBucket: "",
messagingSenderId: "XXXXXX"
}
var defaultApp = firebase.initializeApp(config);
console.log(defaultApp.name);

// Retrieve Firebase Messaging object.
const messaging = firebase.messaging();

messaging.requestPermission().then(function() {
console.log('Notification permission granted.');

}).catch(function(err) {
console.log('Unable to get permission to notify.', err);
});

// Get Instance ID token. Initially this makes a network call, once retrieved
// subsequent calls to getToken will return from cache.
messaging.getToken().then(function(currentToken) {
if (currentToken) {
console.log('token 1 : '+currentToken);
var el = document.getElementById("firebaseToken").value = currentToken;
} else {
console.log('token 2 : '+currentToken)
}
}).catch(function(err) {
console.log('An error occurred while retrieving token. ', err);
});

messaging.onMessage(function(payload) {
console.log("Message received. ", payload);
});


2: index.html



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<textarea id='firebaseToken'></textarea>
</head>
<body>

<!-- Firebase App is always required and must be first -->
<script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-app.js"></script>

<!-- Add additional services that you want to use -->
<script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-functions.js"></script>

<script src="init.js"></script>
</body>
</html>


3: firebase-messaging-sw.js



importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');

const config = {
apiKey: "XXXXX",
authDomain: "XXXXX",
databaseURL: "XXXXXXX",
projectId: "XXXXXXXX",
storageBucket: "",
messagingSenderId: "XXXXXX"
}

var defaultApp = firebase.initializeApp(config);
console.log(defaultApp.name);

const messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
// Customize notification here
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: 'Background Message body.',
icon: '/itwonders-web-logo.png'
};

return self.registration.showNotification(notificationTitle,
notificationOptions);
});


The problem is when I publish my code on Windows hosting, my web app
prototype doesn't get the token (I host in somee.com). But it works fine in 000webhost.com (Linux hosting), and also run with no problem in localhost.



The error says:




code: "messaging/unsupported-browser"
message: "Messaging: This browser doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser)."



stack: "FirebaseError: Messaging: This browser doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser)




Do I have to configure something on Windows server? Open port or etc?



Here's the screenshots:



Screenshot error when hosted in Somee.com (Windows based hosting)Screenshot web work fine in 000webhost










share|improve this question































    0















    I'm new in Firebase, and I am trying to figure out how to make my simple web app get token.



    Since this is just prototype, I have 3 files.



    1: init.js



    // Initialize Firebase
    const config = {
    apiKey: "XXXXX",
    authDomain: "XXXXX",
    databaseURL: "XXXXXXX",
    projectId: "XXXXXXXX",
    storageBucket: "",
    messagingSenderId: "XXXXXX"
    }
    var defaultApp = firebase.initializeApp(config);
    console.log(defaultApp.name);

    // Retrieve Firebase Messaging object.
    const messaging = firebase.messaging();

    messaging.requestPermission().then(function() {
    console.log('Notification permission granted.');

    }).catch(function(err) {
    console.log('Unable to get permission to notify.', err);
    });

    // Get Instance ID token. Initially this makes a network call, once retrieved
    // subsequent calls to getToken will return from cache.
    messaging.getToken().then(function(currentToken) {
    if (currentToken) {
    console.log('token 1 : '+currentToken);
    var el = document.getElementById("firebaseToken").value = currentToken;
    } else {
    console.log('token 2 : '+currentToken)
    }
    }).catch(function(err) {
    console.log('An error occurred while retrieving token. ', err);
    });

    messaging.onMessage(function(payload) {
    console.log("Message received. ", payload);
    });


    2: index.html



    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <textarea id='firebaseToken'></textarea>
    </head>
    <body>

    <!-- Firebase App is always required and must be first -->
    <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-app.js"></script>

    <!-- Add additional services that you want to use -->
    <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-auth.js"></script>
    <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-database.js"></script>
    <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-firestore.js"></script>
    <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-messaging.js"></script>
    <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-functions.js"></script>

    <script src="init.js"></script>
    </body>
    </html>


    3: firebase-messaging-sw.js



    importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
    importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');

    const config = {
    apiKey: "XXXXX",
    authDomain: "XXXXX",
    databaseURL: "XXXXXXX",
    projectId: "XXXXXXXX",
    storageBucket: "",
    messagingSenderId: "XXXXXX"
    }

    var defaultApp = firebase.initializeApp(config);
    console.log(defaultApp.name);

    const messaging = firebase.messaging();

    messaging.setBackgroundMessageHandler(function(payload) {
    console.log('[firebase-messaging-sw.js] Received background message ', payload);
    // Customize notification here
    const notificationTitle = 'Background Message Title';
    const notificationOptions = {
    body: 'Background Message body.',
    icon: '/itwonders-web-logo.png'
    };

    return self.registration.showNotification(notificationTitle,
    notificationOptions);
    });


    The problem is when I publish my code on Windows hosting, my web app
    prototype doesn't get the token (I host in somee.com). But it works fine in 000webhost.com (Linux hosting), and also run with no problem in localhost.



    The error says:




    code: "messaging/unsupported-browser"
    message: "Messaging: This browser doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser)."



    stack: "FirebaseError: Messaging: This browser doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser)




    Do I have to configure something on Windows server? Open port or etc?



    Here's the screenshots:



    Screenshot error when hosted in Somee.com (Windows based hosting)Screenshot web work fine in 000webhost










    share|improve this question



























      0












      0








      0








      I'm new in Firebase, and I am trying to figure out how to make my simple web app get token.



      Since this is just prototype, I have 3 files.



      1: init.js



      // Initialize Firebase
      const config = {
      apiKey: "XXXXX",
      authDomain: "XXXXX",
      databaseURL: "XXXXXXX",
      projectId: "XXXXXXXX",
      storageBucket: "",
      messagingSenderId: "XXXXXX"
      }
      var defaultApp = firebase.initializeApp(config);
      console.log(defaultApp.name);

      // Retrieve Firebase Messaging object.
      const messaging = firebase.messaging();

      messaging.requestPermission().then(function() {
      console.log('Notification permission granted.');

      }).catch(function(err) {
      console.log('Unable to get permission to notify.', err);
      });

      // Get Instance ID token. Initially this makes a network call, once retrieved
      // subsequent calls to getToken will return from cache.
      messaging.getToken().then(function(currentToken) {
      if (currentToken) {
      console.log('token 1 : '+currentToken);
      var el = document.getElementById("firebaseToken").value = currentToken;
      } else {
      console.log('token 2 : '+currentToken)
      }
      }).catch(function(err) {
      console.log('An error occurred while retrieving token. ', err);
      });

      messaging.onMessage(function(payload) {
      console.log("Message received. ", payload);
      });


      2: index.html



      <!DOCTYPE html>
      <html lang="en">
      <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Document</title>
      <textarea id='firebaseToken'></textarea>
      </head>
      <body>

      <!-- Firebase App is always required and must be first -->
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-app.js"></script>

      <!-- Add additional services that you want to use -->
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-auth.js"></script>
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-database.js"></script>
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-firestore.js"></script>
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-messaging.js"></script>
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-functions.js"></script>

      <script src="init.js"></script>
      </body>
      </html>


      3: firebase-messaging-sw.js



      importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
      importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');

      const config = {
      apiKey: "XXXXX",
      authDomain: "XXXXX",
      databaseURL: "XXXXXXX",
      projectId: "XXXXXXXX",
      storageBucket: "",
      messagingSenderId: "XXXXXX"
      }

      var defaultApp = firebase.initializeApp(config);
      console.log(defaultApp.name);

      const messaging = firebase.messaging();

      messaging.setBackgroundMessageHandler(function(payload) {
      console.log('[firebase-messaging-sw.js] Received background message ', payload);
      // Customize notification here
      const notificationTitle = 'Background Message Title';
      const notificationOptions = {
      body: 'Background Message body.',
      icon: '/itwonders-web-logo.png'
      };

      return self.registration.showNotification(notificationTitle,
      notificationOptions);
      });


      The problem is when I publish my code on Windows hosting, my web app
      prototype doesn't get the token (I host in somee.com). But it works fine in 000webhost.com (Linux hosting), and also run with no problem in localhost.



      The error says:




      code: "messaging/unsupported-browser"
      message: "Messaging: This browser doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser)."



      stack: "FirebaseError: Messaging: This browser doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser)




      Do I have to configure something on Windows server? Open port or etc?



      Here's the screenshots:



      Screenshot error when hosted in Somee.com (Windows based hosting)Screenshot web work fine in 000webhost










      share|improve this question
















      I'm new in Firebase, and I am trying to figure out how to make my simple web app get token.



      Since this is just prototype, I have 3 files.



      1: init.js



      // Initialize Firebase
      const config = {
      apiKey: "XXXXX",
      authDomain: "XXXXX",
      databaseURL: "XXXXXXX",
      projectId: "XXXXXXXX",
      storageBucket: "",
      messagingSenderId: "XXXXXX"
      }
      var defaultApp = firebase.initializeApp(config);
      console.log(defaultApp.name);

      // Retrieve Firebase Messaging object.
      const messaging = firebase.messaging();

      messaging.requestPermission().then(function() {
      console.log('Notification permission granted.');

      }).catch(function(err) {
      console.log('Unable to get permission to notify.', err);
      });

      // Get Instance ID token. Initially this makes a network call, once retrieved
      // subsequent calls to getToken will return from cache.
      messaging.getToken().then(function(currentToken) {
      if (currentToken) {
      console.log('token 1 : '+currentToken);
      var el = document.getElementById("firebaseToken").value = currentToken;
      } else {
      console.log('token 2 : '+currentToken)
      }
      }).catch(function(err) {
      console.log('An error occurred while retrieving token. ', err);
      });

      messaging.onMessage(function(payload) {
      console.log("Message received. ", payload);
      });


      2: index.html



      <!DOCTYPE html>
      <html lang="en">
      <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Document</title>
      <textarea id='firebaseToken'></textarea>
      </head>
      <body>

      <!-- Firebase App is always required and must be first -->
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-app.js"></script>

      <!-- Add additional services that you want to use -->
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-auth.js"></script>
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-database.js"></script>
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-firestore.js"></script>
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-messaging.js"></script>
      <script src="https://www.gstatic.com/firebasejs/5.5.9/firebase-functions.js"></script>

      <script src="init.js"></script>
      </body>
      </html>


      3: firebase-messaging-sw.js



      importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
      importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');

      const config = {
      apiKey: "XXXXX",
      authDomain: "XXXXX",
      databaseURL: "XXXXXXX",
      projectId: "XXXXXXXX",
      storageBucket: "",
      messagingSenderId: "XXXXXX"
      }

      var defaultApp = firebase.initializeApp(config);
      console.log(defaultApp.name);

      const messaging = firebase.messaging();

      messaging.setBackgroundMessageHandler(function(payload) {
      console.log('[firebase-messaging-sw.js] Received background message ', payload);
      // Customize notification here
      const notificationTitle = 'Background Message Title';
      const notificationOptions = {
      body: 'Background Message body.',
      icon: '/itwonders-web-logo.png'
      };

      return self.registration.showNotification(notificationTitle,
      notificationOptions);
      });


      The problem is when I publish my code on Windows hosting, my web app
      prototype doesn't get the token (I host in somee.com). But it works fine in 000webhost.com (Linux hosting), and also run with no problem in localhost.



      The error says:




      code: "messaging/unsupported-browser"
      message: "Messaging: This browser doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser)."



      stack: "FirebaseError: Messaging: This browser doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser)




      Do I have to configure something on Windows server? Open port or etc?



      Here's the screenshots:



      Screenshot error when hosted in Somee.com (Windows based hosting)Screenshot web work fine in 000webhost







      javascript firebase firebase-cloud-messaging






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 14:42









      Frank van Puffelen

      245k31390419




      245k31390419










      asked Nov 23 '18 at 12:47









      Wildan NugrahaWildan Nugraha

      185




      185
























          1 Answer
          1






          active

          oldest

          votes


















          1














          I finally got the root cause.



          the reason firebase not running on somee.com.
          Because in somee.com i dont use ssl. but 000webhost got SSL. thats why firebase running on 000webhost.



          because based on this :



          https://github.com/firebase/firebase-js-sdk/issues/1220



          firebase wont running on https not http.



          enter image description here






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447013%2fjavascript-web-firebase-get-token-running-local-but-not-running-in-public-ip%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            I finally got the root cause.



            the reason firebase not running on somee.com.
            Because in somee.com i dont use ssl. but 000webhost got SSL. thats why firebase running on 000webhost.



            because based on this :



            https://github.com/firebase/firebase-js-sdk/issues/1220



            firebase wont running on https not http.



            enter image description here






            share|improve this answer




























              1














              I finally got the root cause.



              the reason firebase not running on somee.com.
              Because in somee.com i dont use ssl. but 000webhost got SSL. thats why firebase running on 000webhost.



              because based on this :



              https://github.com/firebase/firebase-js-sdk/issues/1220



              firebase wont running on https not http.



              enter image description here






              share|improve this answer


























                1












                1








                1







                I finally got the root cause.



                the reason firebase not running on somee.com.
                Because in somee.com i dont use ssl. but 000webhost got SSL. thats why firebase running on 000webhost.



                because based on this :



                https://github.com/firebase/firebase-js-sdk/issues/1220



                firebase wont running on https not http.



                enter image description here






                share|improve this answer













                I finally got the root cause.



                the reason firebase not running on somee.com.
                Because in somee.com i dont use ssl. but 000webhost got SSL. thats why firebase running on 000webhost.



                because based on this :



                https://github.com/firebase/firebase-js-sdk/issues/1220



                firebase wont running on https not http.



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 17:06









                Wildan NugrahaWildan Nugraha

                185




                185
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447013%2fjavascript-web-firebase-get-token-running-local-but-not-running-in-public-ip%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    Origin of the phrase “under your belt”?