Last active
February 18, 2021 19:52
-
-
Save satomiichii/197df3c4c9c3dab3999ab291a6f106c4 to your computer and use it in GitHub Desktop.
Push eventListner in SW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.addEventListener('push', (event) => { | |
let body | |
if (event.data) { | |
//You can set an original message by passing it on the event. | |
body = event.data.text() | |
} else { | |
body = 'Default body' | |
} | |
const options = { | |
body: body, | |
icon: '/your icon image', | |
vibrate: [100, 50, 100], | |
data: { | |
dateOfArrival: Date.now(), | |
primaryKey: 1, | |
}, | |
} | |
event.waitUntil( | |
self.registration.showNotification('Your Message Title', | |
options)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment