检测Chrome中的Rich Notifications是否可用

use*_*107 7 google-chrome-extension rich-notifications

我的Chrome扩展程序大量使用了webkitNotifications.我想切换到新的富通知(chrome.notifications),但这些通知尚未在所有平台上提供,而且仅在beta频道和更高版本中编写.如果富通知不可用,则应将webkitNotifications用作后备.因此,我正在寻找实现这个的最佳解决方案:

if(richNotificationsAvailable())
   chrome.notifications.create(...);
else
   webkitNotifications.createNotification(...).show();
Run Code Online (Sandbox Code Playgroud)

我尝试检查chrome.notifications.create未定义但是甚至为Chrome 27定义了禁用了丰富的通知chrome://flags.

小智 5

为了检测你是否拥有rich notifications,目前最可靠的方法是测试是否存在webkitNotifications.createHTMLNotification- 如果该函数未定义,那么rich notifications就是switched on.