notifications.clear()

Clears a notification, given its ID.

This is an asynchronous function that returns a Promise.

Syntax

js
let clearing = browser.notifications.clear(
  id                            // string
)

Parameters

id

string. The ID of the notification to clear. This is the same as the ID passed into notifications.create()'s callback.

Return value

A Promise that will be fulfilled with a boolean: true if the notification was cleared, or false if it was not (for example, because the notification referenced by id did not exist).

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:

js
let myNotification = "my-notification";

function toggleAlarm(all) {
  if (myNotification in all) {
    browser.notifications.clear(myNotification);
  } else {
    browser.notifications.create(myNotification, {
      type: "basic",
      iconUrl: browser.runtime.getURL("icons/cake-48.png"),
      title: "Am imposing title",
      message: "Some interesting content",
    });
  }
}

function handleClick() {
  let gettingAll = browser.notifications.getAll();
  gettingAll.then(toggleAlarm);
}

browser.browserAction.onClicked.addListener(handleClick);

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
clear
Chrome – Full support
Chrome 28 (Release date: 2013-07-09)
footnote Full support
Edge – Full support
Edge 17 (Release date: 2018-04-30)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 25 (Release date: 2014-10-15)
footnote Full support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 48 (Release date: 2016-08-02)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

Note: This API is based on Chromium's chrome.notifications API.