quickstart-js icon indicating copy to clipboard operation
quickstart-js copied to clipboard

Unable to get Instance ID token

Open ghost opened this issue 10 years ago • 23 comments

After allowing notification permission, I wasn't able to see Instance Token ID on Chrome 54.0.2840.59 (64-bit) version Screenshot: http://prnt.sc/cwkozz

ghost avatar Oct 20 '16 08:10 ghost

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

kroikie avatar Oct 20 '16 10:10 kroikie

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
:


ghost avatar Oct 20 '16 10:10 ghost

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.

ghost avatar Oct 20 '16 12:10 ghost

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

BibleFarm avatar Oct 23 '16 15:10 BibleFarm

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.

ghost avatar Oct 25 '16 06:10 ghost

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?

BibleFarm avatar Oct 25 '16 14:10 BibleFarm

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 ?

riddbengkok avatar Nov 01 '16 06:11 riddbengkok

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 https://github.com/firebase/quickstart-js/issues/69#issuecomment-257500829, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIh8P1KH5mK1m8eOJgPu3qpVv7SNoIbks5q5uH9gaJpZM4Kb1bu .

gauntface avatar Nov 01 '16 14:11 gauntface

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?

riddbengkok avatar Nov 02 '16 06:11 riddbengkok

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) => {
    ....
});

gauntface avatar Nov 04 '16 17:11 gauntface

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"}

19anandp94 avatar Nov 07 '16 12:11 19anandp94

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.

19anandp94 avatar Nov 08 '16 06:11 19anandp94

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

sachinsolanki avatar Dec 14 '16 06:12 sachinsolanki

+1

northoutIshan avatar Dec 25 '16 10:12 northoutIshan

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.

steros76 avatar Dec 31 '16 13:12 steros76

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

GabrielRivera21 avatar Jan 31 '17 18:01 GabrielRivera21

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

karsa87 avatar Mar 06 '17 08:03 karsa87

@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

gauntface avatar Mar 06 '17 19:03 gauntface

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

karsa87 avatar Mar 07 '17 04:03 karsa87

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

MiloslavKrejza avatar Apr 25 '17 20:04 MiloslavKrejza