0

I am creating an google-chrome-extension which has rich notifications. I need to change timeout to close in this notification and I need some help with that. This is my code. I have already tried window.close(), but it does not seem to work in Chrome.

var options = {
  type: "basic",
  title: "test",
  message: "body here",
  iconUrl: "icon.png"
};
var msj = chrome.notifications.create(options);
setTimeout(function () {
  chrome.notifications.clear(msj); // how to close?
}, 1500); 
Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62

1 Answers1

1

Chrome APIs are mostly asynchronous (definitely take a look at that link).

chrome.notifications.create does not immediately create the notification, and will not return the ID. You need to use the callback for that:

chrome.notifications.create(options, function(msj) {
  setTimeout(function() {
    chrome.notifications.clear(msj);
  }, 1500); 
});
Xan
  • 74,770
  • 16
  • 179
  • 206