Lancé immédiatement après l'affichage d'une notification.
Syntaxe
browser.notifications.onShown.addListener(listener)
browser.notifications.onShown.removeListener(listener)
browser.notifications.onShown.hasListener(listener)
Les événements ont trois fonctions :
addListener(callback)
- Ajoute un écouteur à cet événement.
removeListener(listener)
- Arrêtez d'écouter cet événement. L'argument
listener
est l'écouteur à supprimer. hasListener(listener)
- Vérifiez si
listener
est enregistré pour cet événement. Renvoietrue
s'il écoute, sinonfalse
.
syntaxe addListener
Paramètres
callback
-
Fonction qui sera appelée lorsque cet événement se produit. La fonction recevra les arguments suivants :
notificationId
string
. ID de la notification qui a été affichée.
Compatibilité du navigateur
BCD tables only load in the browser
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.
Exemples
Ajoutez un écouteur à l'événement notifications.onShown
et consignez ses détails :
function logShown(itemId) {
console.log(`shown: ${itemId}`);
browser.notifications.getAll().then((all) => {
console.log(all[itemId]);
})
}
browser.notifications.onShown.addListener(logShown);
Remerciements :
Cette API est basée sur l'API Chromium chrome.notifications
.