Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if Rich Notifications in Chrome are available

My Chrome extension makes heavy use of webkitNotifications. I want to switch to the new rich notifications (chrome.notifications) but those aren't available on all platforms yet and at the moment of writing only in the beta channel and up. If the rich notifications aren't available webkitNotifications should be used as fallback. Thus I'm looking for the best solution to implement this:

if(richNotificationsAvailable())
   chrome.notifications.create(...);
else
   webkitNotifications.createNotification(...).show();

I tried checking chrome.notifications.create for undefined but it's even defined for Chrome 27 with the rich notifications disabled in chrome://flags.

like image 870
user2425107 Avatar asked May 27 '13 13:05

user2425107


1 Answers

To detect if you have rich notifications, the most reliable way is currently to test for the existence of webkitNotifications.createHTMLNotification - if that function is undefined, then rich notifications have been switched on.

like image 133
Somas T Avatar answered Oct 02 '22 03:10

Somas T