Comments (23)
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.
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.
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.
If the IID token generation fails, it should be logged in the console, are you seeing any error message there?
from quickstart-js.
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.
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.
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.
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.
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.
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.
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.
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.
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.
I got same problem with all browser, When I am trying with my hosting server.
from quickstart-js.
+1
from quickstart-js.
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.
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.
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.
@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.
@gauntface thank you, for your suggestion. it worked well.
from quickstart-js.
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.
@MiloslavKrejza Please continue discussing this on the other issue on this repo that you've commented on.
from quickstart-js.
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)
- i dont want to show message onbackground because crashing with hundreds notification.
- before online after offline to much notification, there is any to check its last notification ? to prevent some trigger.
- Enter Custom Auth Code
- wrong README.md
- Problems integrating Firebase service woker with existing service-worker of react PWA HOT 1
- [Firebase Cloud Messaging Quickstart] Should be updated to use Firebase Cloud Messaging API (V1)
- Messaging: We are unable to register the default service worker. HOT 2
- Show two messages HOT 1
- Auth in chrome extension is not working
- The "Send Code" button for MFA is never enabled even after entering valid phone number and successful recaptcha HOT 1
- FCM HTTP V1 API
- Cors policy no longer allows calling cloud functions from browser. HOT 6
- Unable to start firebase project for existing instruction
- The GitHub authentication component is used on the Google Authentication page
- Server Key
- messaging quickstart does not work HOT 3
- not working the firebase config HOT 1
- Incorrect script in firestore quickstart readme
- Why can’t I get currentUser on my iPhone? HOT 1
- Fetch data from mobile is 35 times slower than on PC
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quickstart-js.