Clears a notification, given its ID.
Syntax
chrome.notifications.clear( id, // string function(wasCleared) {...} // optional function )
This API is also available as browser.notifications.clear()
in a version that returns a promise.
Parameters
id
string
. The ID of the notification to clear. This is the same as the ID passed intonotifications.create()
's callback.callback
Optionalfunction
. The function is passed the following arguments:-
wasCleared
boolean
.true
if the notification was cleared, 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 | 45.0 | 48.0 | 33 |
Examples
This example shows a notification when the user clicks a browser action, unless the notification was already being shown, in which case it clears the notification:
var myNotification = "my-notification"; chrome.browserAction.onClicked.addListener(function () { chrome.notifications.getAll((all) => { if (myNotification in all) { chrome.notifications.clear(myNotification); } else { chrome.notifications.create(myNotification, { "type": "basic", "iconUrl": chrome.extension.getURL("icons/cake-48.png"), "title": "Am imposing title", "message": "Some interesting content" }); } }); });
Acknowledgements
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.