Tuesday, February 1, 2011

Desktop / Web notifications

Inspired by GMail's recent release of Desktop Notifications, I decided to research the feasibility of using them to replace the notification area for an application I work on. Since I develop for a small internal group I can target newer browsers such as Chrome and Firefox.

The W3C specification for Web Notifications is still in draft but outlines the concept well. The website must request permission and then may publish notifications for the browser to display.

Google Chrome / Chromium
Chromium has published their API specification and it closely resembles the W3C specification. The onclick attribute is currently missing and onshow is called ondisplay.

Sadly Firefox 4 will not have support for Web Notifications. Bug 594543 is currently tracking the implementation for a future version but does not have a milestone listed. It's slightly concerning that the bug author is already suggesting a deviation from the W3C specification - they would rather include a callback on the Notification constructor instead of implementing the onshow, onclick, onerror, and onclose attributes.


The last example uses setTimeout to call cancel after 15 seconds. This seems like a good way to ensure the popup is closed; however, I'm slightly surprised they did not call setTimeout within the Notification's onshow method. Unless the notification is immediately displayed the setTimeout timer is needlessly wasting time. The rationale for this choice may be because there is no guarantee that the onshow method will be called immediately.

No comments:

Post a Comment