browserSettings.webNotificationsDisabled
一個 BrowserSetting 物件,可用於阻止網站使用 Notifications Web API 顯示通知。
Notifications API 用於向用戶顯示桌面通知。通知有三個許可權級別:允許、拒絕 和 提示。使用者可以為每個網站設定此許可權。如果使用者未為特定網站設定許可權,則瀏覽器將回退到全域性許可權,而全域性許可權預設為提示。
將 browserSettings.webNotificationsDisabled 設定為 true 會將全域性許可權切換為拒絕。
請注意,這不會影響使用者已為之設定了站點內偏好的網站。例如,如果使用者將 https://example.org 設定為允許,然後擴充套件將 browserSettings.webNotificationsDisabled 設定為 true,那麼 https://example.org 下的頁面仍將允許顯示通知。
將 browserSettings.webNotificationsDisabled 設定為 false 會將全域性預設值恢復為預設值。
請注意,此設定不會影響使用 notifications API 建立的擴充套件通知。
示例
切換設定
js
async function toggleWebNotifications() {
let current = await browser.browserSettings.webNotificationsDisabled.get({});
console.log(`Current value: ${current.value}`);
browser.browserSettings.webNotificationsDisabled.set({
value: !current.value,
});
}
browser.browserAction.onClicked.addListener(() => {
toggleWebNotifications();
});
瀏覽器相容性
載入中…