GithubHelp home page GithubHelp logo

Comments (23)

gauntface avatar gauntface commented on June 15, 2024 3

The 'firebase-messaging-sw.js' file needs to be at the root of your project.

If you can't do that you can use the useServiceWorker(registration) method which would look something like this:

navigator.serviceworker.register('/app/path/example/sw.js')
.then((registration) => {
    const messaging = firebase.messaging();
    messaging.useServiceWorker(registration);
    return messaging.getToken();
})
.then((token) => {
    ....
});

from quickstart-js.

saiprasad08dhumal avatar saiprasad08dhumal commented on June 15, 2024 2

I prefer to use useServiceWorker using the following syntax
firebase.messaging().useServiceWorker(registration)
what should be the value of registration object that we pass in here?
It should point to my firebase_ServiceWorker.js file in same directory. which contains:
//start of firebase_ServiceWorker
firebase.initializeApp({
'messagingSenderId': '103953800507'
});
const messaging = firebase.messaging();
//END of firebase_ServiceWorker
After this is done, I expect to get FCM token on web.

from quickstart-js.

riddbengkok avatar riddbengkok commented on June 15, 2024 1

yess i got it , the problem is , script read server worker in http://localhost/firebase-messaging-sw.js , not in my app folder http://localhost/firebase/quickstart/messaging , so i must add file firebase-messaging-sw.js in root of folder localhost (/var/ww/html) , i dont know but its work

thank for answer mr @gauntface

but how to fx this ,to read firrebase-messaging-sw.js in my app directory?

from quickstart-js.

kroikie avatar kroikie commented on June 15, 2024

If the IID token generation fails, it should be logged in the console, are you seeing any error message there?

from quickstart-js.

 avatar commented on June 15, 2024

I have tried on windows Chrome and it is giving error:
browserErrorMessage
:
"Failed to register a ServiceWorker: ServiceWorker script evaluation failed"
code
:
"messaging/failed-serviceworker-registration"
message
:
"Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: ServiceWorker script evaluation failed (messaging/failed-serviceworker-registration)."
stack
:
(...)
get stack
:


from quickstart-js.

 avatar commented on June 15, 2024

but on MAC OS Chrome , it was just saying "loading..." No error was available in the console. The test has been done Over https connections. Firefox is working on both Windows and MacOS platform. Only I am getting the problem with Chrome.

from quickstart-js.

BibleFarm avatar BibleFarm commented on June 15, 2024

I think I'm missing something...
http://www.solidarityfarm.tk/quickstart-js-master/messaging/index.html

This below is the only error I'm getting with Firefox 49.0.2 :
An error occurred while retrieving token. Object { code: "messaging/unsupported-browser", message: "Messaging: This browser doesn't sup…", name: "FirebaseError", stack: "", 1 more

from quickstart-js.

 avatar commented on June 15, 2024

With above URL http://www.solidarityfarm.tk/quickstart-js-master/messaging/index.html I am getting "Only secure origins are allowed (see: https://goo.gl/Y0ZkNV)." error in console.

from quickstart-js.

BibleFarm avatar BibleFarm commented on June 15, 2024

Thank you for trying it inautus :) I appreciate that.
Should I ask my hosting service to put my URL in an https:// in order for this messaging to work? Or is there another way to make it work?

from quickstart-js.

riddbengkok avatar riddbengkok commented on June 15, 2024

i have eror too , like @inautus error:
browserErrorMessage
:
"Failed to register a ServiceWorker: ServiceWorker script evaluation failed"
code
:
"messaging/failed-serviceworker-registration"
message
:
"Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: ServiceWorker script evaluation failed (messaging/failed-serviceworker-registration)

runing in localhost/firebase/quickstart/messaging
anyone can hlep ?

from quickstart-js.

gauntface avatar gauntface commented on June 15, 2024

The "script evaluation failed" normally means there was a problem with the
javascript in the service worker file.

Does it link to a line number? Also are you starting the server in the
messaging folder?

Matt

On Mon, 31 Oct 2016, 23:53 alfat osk, [email protected] wrote:

i have eror too , like @inautus https://github.com/inautus error:
browserErrorMessage : "Failed to register a ServiceWorker: ServiceWorker
script evaluation failed" code :
"messaging/failed-serviceworker-registration" message : "Messaging: We are
unable to register the default service worker. Failed to register a
ServiceWorker: ServiceWorker script evaluation failed
(messaging/failed-serviceworker-registration)

runing in localhost/firebase/quickstart/messaging
anyone can hlep ?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#69 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAIh8P1KH5mK1m8eOJgPu3qpVv7SNoIbks5q5uH9gaJpZM4Kb1bu
.

from quickstart-js.

19anandp94 avatar 19anandp94 commented on June 15, 2024

I am getting the similar error as following:

An error occurred while retrieving token. V {code: "messaging/failed-serviceworker-registration", message: "Messaging: We are unable to register the default s…t. (messaging/failed-serviceworker-registration).", browserErrorMessage: "Failed to register a ServiceWorker: A bad HTTP res…code (404) was received when fetching the script.", stack: "FirebaseError: Messaging: We are unable to registe….gstatic.com/firebasejs/3.5.1/firebase.js:537:225"}

from quickstart-js.

19anandp94 avatar 19anandp94 commented on June 15, 2024

And It is working fine and generating token on the chrome's localhost server but not working on my hosting server.
Please Help! on issue.

from quickstart-js.

sachinsolanki avatar sachinsolanki commented on June 15, 2024

I got same problem with all browser, When I am trying with my hosting server.

from quickstart-js.

northoutIshan avatar northoutIshan commented on June 15, 2024

+1

from quickstart-js.

steros76 avatar steros76 commented on June 15, 2024

I have the same problem. Analysing the code I saw the worker is registered as '/firebase-messaging-sw.js', so, putting 'firebase-messaging-sw.js' on website root, it works correctly.
It seems to me it's a bug.

from quickstart-js.

GabrielRivera21 avatar GabrielRivera21 commented on June 15, 2024

Yeah, it seems that you need to set up an SSL certificate in your domain. In localhost it will run fine, but, in order for a service worker to start, it must come from a secure origin meaning it has to come through the "https" protocol

from quickstart-js.

karsa87 avatar karsa87 commented on June 15, 2024

solved this problem by changing the file firebase.js
on line :
return navigator.serviceWorker.register("/firebase-messaging-sw.js",{scope:"/firebase-cloud-messaging-push-scope"})

change :
return navigator.serviceWorker.register("firebase-messaging-sw.js",{scope:"firebase-cloud-messaging-push-scope"})

and I made a folder firebase-cloud-messaging-push-scope with firebase.js files in it

from quickstart-js.

gauntface avatar gauntface commented on June 15, 2024

@karsa87 The better solution is to do as you are and call useServiceWorker() to use a service worker if the location of the service worker file is a problem: https://firebase.google.com/docs/reference/js/firebase.messaging.Messaging#useServiceWorker

from quickstart-js.

karsa87 avatar karsa87 commented on June 15, 2024

@gauntface thank you, for your suggestion. it worked well.

from quickstart-js.

MiloslavKrejza avatar MiloslavKrejza commented on June 15, 2024

Hello i'm having the same issue
FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration).
at http://localhost:5000/__/firebase/3.8.0/firebase.js:544:225

I have my firebase-messaging-sw.js file in a root directory and it still giving me a error, what is the problem?
Please help

from quickstart-js.

gauntface avatar gauntface commented on June 15, 2024

@MiloslavKrejza Please continue discussing this on the other issue on this repo that you've commented on.

from quickstart-js.

akash710 avatar akash710 commented on June 15, 2024

i am unable to generate the token in http localhost, what could be the reason? I don't see any error in console

from quickstart-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.