SECURITY_ERR: DOM Exception 18 valid if the user did not allow your request to receive notifications.
The reason this happens is simply because requestPermission is asynchronous. After the user clicks on Allow to get permission, he will allow you to use the HTML5 notification function.
In your case, without waiting for the user to click the Allow button, he automatically tries to create an HTML5 notification, without waiting for confirmation of his time. If you change your conventions, it should work.
function RequestPermission(callback) { window.webkitNotifications.requestPermission(callback); } function notif() { if (window.webkitNotifications.checkPermission() > 0) { RequestPermission(notif); } else { notification = window.webkitNotifications.createHTMLNotification('http://localhost:3000/images/rails.png'); notification.show(); } }
As you noted above, place the creation of a notification in a conditional expression, when the callback is launched, it will be guaranteed permission.
source share