Anne van Kesteren

End-user notifications

It has taken a little while, but thanks in part due to interest from Apple and some editing by yours truly it seems like the API for end-user notifications for the platform is now more or less finished: Web Notifications. Once implemented in browsers this will let applications interact with native notification platforms, such as libnotify on GNOME. If you have feedback you can email the archived public-web-notification mailing list.

Showing a notification is trivial:

new Notification("Hello world!", {iconUrl:"/img/notify"})

But before you can show notifications your application needs to ask permission to the user. Permissions for applications is a hard problem and unfortunately end-user notifications is a rare case that requires the “worst” solution. Programming-wise it is pretty trivial though:

var canShowNotifications = false
if(Notification.permission == "granted") {
  canShowNotifications = true
} else if (Notification.permission == "default") {
  Notification.requestPermission(function(perm) { 
    canShowNotifications = perm == "granted"