const myNotification = "my-notification";
function toggleAlarm(all) {
const ids = Object.keys(all);
if (ids.includes(myNotification)) {
browser.notifications.clear(myNotification);
} else {
console.log("showing");
browser.notifications.create(myNotification, {
type: "basic",
title: "Am imposing title",
message: "Some interesting content",
});
}
}
function handleClick() {
console.log("clicked");
browser.notifications.getAll().then(toggleAlarm);
}
browser.browserAction.onClicked.addListener(handleClick);notifications.getAll() / notebook
notifications.getAll()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
function logNotifications(all) {
for (const id in all) {
console.log(`Title: ${all[id].title}`);
}
}
browser.notifications.getAll().then(logNotifications);