kidsil
April 28, 2020, 5:29pm
1
Hi there,
I’m trying to change the Notification permissions for a given website.
I was able to fetch the current permission via:
const result = await browser.tabs.executeScript(tabId, {code:'Notification.permission'});
I’m not sure however how to set the Notification permission for a given website…?
Thanks a lot in advance!
sylvaing
(Sylvain Giroux)
April 28, 2020, 5:40pm
2
Hi,
The ‘permission’ property is read-only. It indicates the current permission granted by the user.
Only the user can change this permission. The user prompt can be shown via https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission
kidsil
April 29, 2020, 7:30am
3
Is there a way to temporarily block Notifications coming from a specific tab (programmatically, of course)?
Sure, you can overwrite the notification APIs and ignore the calls. Note that this does not work for service workers.
Example content script that intercepts the notification APIs:
"use strict";
/* global cloneInto, exportFunction */
//TODO handle renotify & tag
const OPTIONS_INDEX = 1,
dispatchNotificationEvent = (options) => {
if(Notification.permission === "granted" && (!options || !options.silent)) {
if(!options || !options.sound) {
browser.runtime.sendMessage("new-notification");
}
else {
browser.runtime.sendMessage({
command: 'play',
url: new URL(options.sound, window.location).toString()
});
}
}
},
OriginalNotification = window.wrappedJSObject.Notification,
/**
This file has been truncated. show original