webkitnotifications 在 Chrome 中不起作用

webkitnotifications doesn't work in Chrome

我有一个显示通知的扩展程序,在 chrome 更新之前工作正常,但不再与 Chrome 一起工作。

我应该对此代码进行哪些编辑才能使其正常工作。 这是我的代码。

deskNoti=webkitNotifications.createNotification(chrome.app.getDetails().name,'You have '+counter+' new messages');
deskNoti.onclick=function(){openPage();this.cancel()
};
deskNoti.show();
 
if(timeNoti){window.setTimeout(function(){deskNoti.cancel();},timeNoti);}

webkitNotifications 已被删除。直接替换为Notifications API.

代码很容易翻译:

// Instead of calling a create function, one calls the "new" operator:
deskNoti = new Notification(
  chrome.app.getDetails().name,
  // Instead of just message text, the second parameter is now an object
  //  with multiple properties. Message text should go into "body" parameter:
  { body: 'You have '+counter+' new messages' }
);

// Instead of .cancel(), the function to close the notification is now .close()
deskNoti.onclick = function() { openPage(); this.close() };

// Notifications are now shown automatically; there is no .show() function
//deskNoti.show();

if(timeNoti) {
  window.setTimeout(function() { deskNoti.close(); }, timeNoti);
}

考虑改用 chrome.notifications API