Last active
August 26, 2019 13:16
-
-
Save Spyna/f38de40ed2b18282b0aa692f5076023f to your computer and use it in GitHub Desktop.
How to show a web push notification
This file contains hidden or 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
const img = "/images/jason-leung-HM6TMmevbZQ-unsplash.jpg"; | |
const text = "Take a look at this brand new t-shirt!"; | |
const title = "New Product Available"; | |
const options = { | |
body: text, | |
icon: "/images/jason-leung-HM6TMmevbZQ-unsplash.jpg", | |
vibrate: [200, 100, 200], | |
tag: "new-product", | |
image: img, | |
badge: "https://spyna.it/icons/android-icon-192x192.png", | |
actions: [{ action: "Detail", title: "View", icon: "https://via.placeholder.com/128/ff0000" }] | |
}; | |
navigator.serviceWorker.ready.then(function(serviceWorker) { | |
serviceWorker.showNotification(title, options); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment