Open aleha84 opened 7 years ago
Please be aware that Chrome on Android won't support desktop notifications through new Notification(…)
. See this issue and that one.
This issue should be marked as a bug because pNotify desktop module will fail on that platform.
Using ServiceWorker notifications is out of the scope of pNotify, so the solution should be, like some contributors noted, trying creating a Notification
object first and catching the exception if any:
function isNewNotificationSupported() {
if (!window.Notification || !Notification.requestPermission)
return false;
if (Notification.permission == 'granted')
throw new Error('You must only call this *before* calling Notification.requestPermission(), otherwise this feature detect would bug the user with an actual notification!');
try {
new Notification('');
} catch (e) {
if (e.name == 'TypeError')
return false;
}
return true;
}
This code should be used in Component.permission
in PNotifyDesktop.html
This issue is related too #289
Chrome mobile will not show native browser notifications via
new Notification(...)
. It uses modern Service Workers approach. Here is a link for solutions of how to show and how to detect this behavior.