You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
importScripts('https://www.gstatic.com/firebasejs/7.14.5/firebase-app.js'); |
|
importScripts('https://www.gstatic.com/firebasejs/7.14.5/firebase-messaging.js'); |
|
|
|
firebase.initializeApp({ |
|
apiKey: "AIzaSyCJtXpg5jFDtuEWy4f4dajX_NKHStZAtVQ", |
|
authDomain: "my-tasks-98409.firebaseapp.com", |
|
databaseURL: "https://my-tasks-98409.firebaseio.com", |
|
projectId: "my-tasks-98409", |
|
storageBucket: "my-tasks-98409.appspot.com", |
|
messagingSenderId: "411418171487", |
|
appId: "1:411418171487:web:fbbe0d70a1376f2d64e3ea" |
|
}); |
|
|
|
const messaging = firebase.messaging(); |
|
|
|
messaging.setBackgroundMessageHandler(function(payload) { |
|
const promiseChain = clients |
|
.matchAll({ |
|
type: "window", |
|
includeUncontrolled: true |
|
}) |
|
.then(windowClients => { |
|
for (let i = 0; i < windowClients.length; i++) { |
|
const windowClient = windowClients[i]; |
|
windowClient.postMessage(payload); |
|
} |
|
}) |
|
.then(() => { |
|
return registration.showNotification("my notification title"); |
|
}); |
|
return promiseChain; |
|
}); |
|
|
|
self.addEventListener('notificationclick', function(event) { |
|
// do what you want |
|
// ... |
|
}); |