notifications.clear()
Efface une notification, compte tenu de son identifiant.
C'est une fonction asynchrone qui renvoie une Promise.
Syntaxe
js
var clearing = browser.notifications.clear(
id, // string
);
Paramètres
id-
string. L'ID de la notification à effacer. C'est la même chose que l'ID transmis dans le callbacknotifications.create().
Valeur retournée
Une Promise qui sera remplie avec un booléen : true la notification a été effacée, ou false si ce n'est pas le cas (par exemple, parce que la notification référencée par id n'existe pas).
Compatibilité des navigateurs
Chargement…
Exemples
Cet exemple affiche une notification lorsque l'utilisateur clique sur une action du navigateur, à moins que la notification ne soit déjà affichée, auquel cas il efface la notification :
js
var myNotification = "my-notification";
function toggleAlarm(all) {
if (myNotification in all) {
browser.notifications.clear(myNotification);
} else {
browser.notifications.create(myNotification, {
type: "basic",
iconUrl: browser.extension.getURL("icons/cake-48.png"),
title: "Am imposing title",
message: "Some interesting content",
});
}
}
function handleClick() {
var gettingAll = browser.notifications.getAll();
gettingAll.then(toggleAlarm);
}
browser.browserAction.onClicked.addListener(handleClick);
Note :
Cette API est basée sur l'API Chromium chrome.notifications.