Skip to content

Instantly share code, notes, and snippets.

@satomiichii
Last active February 18, 2021 19:52
Show Gist options
  • Save satomiichii/197df3c4c9c3dab3999ab291a6f106c4 to your computer and use it in GitHub Desktop.
Save satomiichii/197df3c4c9c3dab3999ab291a6f106c4 to your computer and use it in GitHub Desktop.
Push eventListner in SW
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