Skip to content

Instantly share code, notes, and snippets.

@Troland
Created June 25, 2018 15:58
Show Gist options
  • Save Troland/ab85553dbfdf42921f89115be26e8751 to your computer and use it in GitHub Desktop.
Save Troland/ab85553dbfdf42921f89115be26e8751 to your computer and use it in GitHub Desktop.
requestPermission for web push notifications
function requestPermission() {
return new Promise((resolve, reject) => {
const permissionResult = Notification.requestPermission((result) => {
// Handling deprecated version with callback.
resolve(result);
});
if (permissionResult) {
permissionResult.then(resolve, reject);
}
})
.then((permissionResult) => {
if (permissionResult !== 'granted') {
throw new Error('Permission not granted.');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment