Skip to content

Instantly share code, notes, and snippets.

@zlatkov
Created February 28, 2018 14:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zlatkov/54535c87cfda64986d554d256021e0ad to your computer and use it in GitHub Desktop.
Save zlatkov/54535c87cfda64986d554d256021e0ad to your computer and use it in GitHub Desktop.
function requestPermission() {
return new Promise(function(resolve, reject) {
const permissionResult = Notification.requestPermission(function(result) {
// Handling deprecated version with callback.
resolve(result);
});
if (permissionResult) {
permissionResult.then(resolve, reject);
}
})
.then(function(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