0

I have a extension that shows a notifications, and worked fine until chrome updating and doesn't work any more with Chrome.

What I should edit on this code to make it working. here is my code.

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);}
Alex
  • 91
  • 1
  • 10
  • 1
    They have been removed. You need to rework your code to work with either [Notification API](https://developer.mozilla.org/en/docs/Web/API/notification) or [`chrome.notifications` API](https://developer.chrome.com/extensions/notifications) – Xan Apr 25 '15 at 16:30
  • so there is no way to make this code working? – Alex Apr 25 '15 at 16:30
  • Yes, there is. The direct successor is `Notification` API. It's slightly different, but it should not be hard to adapt code. – Xan Apr 25 '15 at 16:31
  • How can do that? Can you help me? – Alex Apr 25 '15 at 16:33

1 Answers1

1

webkitNotifications has been removed. The direct replacement is Notifications API.

The code is easy to translate:

// 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);
}

Consider using chrome.notifications API instead.

Xan
  • 74,770
  • 16
  • 179
  • 206