Updates a notification, given its ID.
Syntax
chrome.notifications.update( id, // string options, // NotificationOptions function(wasUpdated) {...} // optional function )
This API is also available as browser.notifications.update()
in a version that returns a promise.
Parameters
id
string
. The ID of the notification to update. This is the same as the ID passed intonotifications.create()
's callback.options
notifications.NotificationOptions
. Defines the notification's new content and behavior.callback
Optionalfunction
. The function is passed the following arguments:-
wasUpdated
boolean
.true
if the notification was updated, orfalse
if it was not (for example, because the notification referenced byid
did not exist).,
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Chrome | Edge | Firefox | Firefox for Android | Opera | |
---|---|---|---|---|---|
Basic support | Yes | No | No | No | 33 |
Compatibility notes
Opera
- Not supported on Macs.
Examples
This example uses update()
to update a progress notification. Clicking the browser action shows the notification and starts an alarm
, which we use to update the notification's progress indicator.
Note that you'll need the "alarms" permission to create alarms (as well as the "notifications" permission to create notifications). Also note that Firefox does not support the progress
attribute.
var cakeNotification = "cake-notification"; /* CAKE_INTERVAL is set to 0.3 seconds in this example. Such a short period is chosen to make the add-on's behavior more obvious, but this is not recommended in real life. Note that in Chrome, alarms cannot be set for less than a minute. */ var CAKE_PREP_INTERVAL = 0.005; var progress = 0; chrome.alarms.onAlarm.addListener(function(alarm) { progress = progress + 10; if (progress > 100) { chrome.notifications.clear(cakeNotification); chrome.alarms.clear("cake-progress"); } else { chrome.notifications.update(cakeNotification, { "progress": progress }); } }); chrome.browserAction.onClicked.addListener(function () { chrome.notifications.getAll((all) => { if (all.length > 0) { chrome.notifications.clear(cakeNotification); return; } progress = 0; chrome.notifications.create(cakeNotification, { "type": "progress", "iconUrl": chrome.extension.getURL("icons/cake-48.png"), "title": "Your cake is being prepared...", "message": "Something something cake", "progress": progress }); chrome.alarms.create( "cake-progress", {periodInMinutes: CAKE_PREP_INTERVAL} ); }); });
This API is based on Chromium's chrome.notifications
API.
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.