What is the correct way to check the permission for the web browser notification? I am using notify.js from this https://github.com/alexgibson/notify.js/
I already follow the pattern from example, but i still get this error: "You must only call this before calling Notification.requestPermission(), otherwise this feature detect would trigger an actual notification!".
This is my method:
showNotification() {
if (!Notify.needsPermission) {
doNotification();
} else if (Notify.isSupported()) {
Notify.requestPermission(notifyStatus.onPermissionGranted, notifyStatus.onPermissionDenied);
}
}
And this is the method in notify.js for Notify.isSupported:
Notify.isSupported = function(perm) {
if (!N || !N.requestPermission) {
return false;
}
if (perm === 'granted' || N.permission === 'granted') {
throw new Error('You must only call this before calling Notification.requestPermission(), otherwise this feature detect would trigger an actual notification!');
}
try {
new N('');
} catch (e) {
if (e.name === 'TypeError') {
return false;
}
}
return true;
};
Please help, thanks.
Aucun commentaire:
Enregistrer un commentaire