Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't get token #208

Closed
MiloslavKrejza opened this issue Apr 26, 2017 · 5 comments
Closed

I can't get token #208

MiloslavKrejza opened this issue Apr 26, 2017 · 5 comments
Assignees

Comments

@MiloslavKrejza
Copy link

MiloslavKrejza commented Apr 26, 2017

hello i can't get token from a database

"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)."

What can i do to fix this?

@annetters
Copy link

annetters commented May 2, 2017

I am also having this issue. This comes up on Step 9 of the tutorial, right after you ask the user to accept notifications.
As a user, I receive the request to Get Notifications and hit Accept. Afterwards, the console reads:

A bad HTTP response code (404) was received when fetching the script. :5001/__/firebase/3.8.0/firebase-app.js 

Failed to load resource: net::ERR_INVALID_RESPONSE firebase-messaging-sw.js:1 

Uncaught [object DOMException] (anonymous) @ firebase-messaging-sw.js:1
main.js:237 

Unable to get messaging token. e {code: "messaging/failed-serviceworker-registration", message: "Messaging: We are unable to register the default s…ed (messaging/failed-serviceworker-registration).", 

browserErrorMessage: "Failed to register a ServiceWorker: ServiceWorker script evaluation failed", stack: "FirebaseError: Messaging: We are unable to registe….gstatic.com/firebasejs/3.8.0/firebase.js:544:225"}
(anonymous) @ main.js:237

@surazzarus
Copy link

I am having the same problem. Could anyone find the solution for this? Thanks

@kroikie kroikie self-assigned this Jun 1, 2017
@Krupen
Copy link

Krupen commented Jun 8, 2017

After spending lot of time, I found a solution. This is something that they din't put up in the documentation.

You need to add firebase-messaging-sw.js named file with following content to your root (/public) directory
`

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


var config = {
    apiKey: "<APIKEY>",
    authDomain: "<PROJECTID>.firebaseapp.com",
    databaseURL: "https://<DATABASE NAME>.firebaseio.com",
    projectId: "<PROJECT ID>",
    storageBucket: "<PROJECT ID>.appspot.com",
    messagingSenderId: "<SENDER ID>"
};
firebase.initializeApp(config);
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: '/firebase-logo.png'
    };

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

`

@kroikie
Copy link
Contributor

kroikie commented Jul 19, 2017

This issue was moved to firebase/codelab-friendlychat-android#4

@jenvigo
Copy link

jenvigo commented Jun 3, 2022

After spending lot of time, I found a solution. This is something that they din't put up in the documentation.

You need to add firebase-messaging-sw.js named file with following content to your root (/public) directory `

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


var config = {
    apiKey: "<APIKEY>",
    authDomain: "<PROJECTID>.firebaseapp.com",
    databaseURL: "https://<DATABASE NAME>.firebaseio.com",
    projectId: "<PROJECT ID>",
    storageBucket: "<PROJECT ID>.appspot.com",
    messagingSenderId: "<SENDER ID>"
};
firebase.initializeApp(config);
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: '/firebase-logo.png'
    };

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

`

This is not working for me... Actually, the file is being generated after building the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants