My Chrome extension heavily uses webkitNotifications. I want to switch to new rich notifications (chrome.notifications) , but they are not yet available on all platforms and at the time of writing in the beta channel and up. If rich notifications are not available, then webkitNotifications should be used as a reserve. So I'm looking for a better solution to implement this:
if(richNotificationsAvailable()) chrome.notifications.create(...); else webkitNotifications.createNotification(...).show();
I tried checking chrome.notifications.create for undefined, but it is even defined for Chrome 27 with rich notifications turned off in chrome://flags .
chrome.notifications.create
chrome://flags
To determine if you have rich notifications , the most reliable way is to check for the existence of webkitNotifications.createHTMLNotification - if this function is undefined, then rich notifications were switched on .
rich notifications
webkitNotifications.createHTMLNotification
switched on
Just use this code:
if (webkitNotifications && webkitNotifications.createHTMLNotification) { //HTML notifications } else if (chrome.notifications && chrome.notifications.create) { //Rich notifications }