Skip to content

Instantly share code, notes, and snippets.

@novaknole
Created February 21, 2020 14:25
Show Gist options
  • Save novaknole/5594c3603257cbd62dd3e377548a9ec1 to your computer and use it in GitHub Desktop.
Save novaknole/5594c3603257cbd62dd3e377548a9ec1 to your computer and use it in GitHub Desktop.
function askPermission() {
return new Promise(function(resolve, reject) {
const permissionResult = Notification.requestPermission(function(result) {
resolve(result);
});
if (permissionResult) {
permissionResult.then(resolve, reject);
}
})
.then(function(permissionResult) {
if (permissionResult !== 'granted') {
throw new Error('We weren\'t granted permission.');
}
});
}
askPermission().then(d => {
navigator.serviceWorker.ready
.then(function(swreg) {
console.log("blaxblux");
swreg.showNotification('Successfully subscribed!', {body:'giorgi'});
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment