Reputation: 117
I'm developing an extension with chrome.notifications would like to set a time for closing the notification, how can I do this?
Upvotes: 8
Views: 12540
Reputation: 77523
Chrome automatically hides the notification. How long it stays on screen depends on the priority
attribute. Note that everywhere except Chrome OS the hidden notification is effectively closed, as the Notification Center was removed.
It's possible to keep the notification shown, but you'll have to resort to dirty tricks. If you don't want to do it the hard way, consider using Web Notifications instead - they will not be hidden.
Update: Both chrome.notifications
and Web Notifications APIs now implement a boolean flag requireInteraction
that defines whether Chrome will fade the notification away automatically or not.
You can still manually close (i.e., remove completely) the notification by calling chrome.notifications.clear()
with the notification ID.
To schedule something, you can either use DOM intervals, or chrome.alarms
API.
Upvotes: 11
Reputation: 1563
I'm using this in my project
var opt = {type, title, message, etc....}
chrome.notifications.create("", opt, function(id) {
timer = setTimeout(function(){chrome.notifications.clear(id);}, 2000);
});
notification is closed after 2 sec (2000 ms)
Upvotes: 5