I am currently developing a Chrome extension that is designed to take specific actions when system notifications appear, with the main goal being to close them automatically.
One example of such a notification is the "Restore pages?" prompt:
https://i.stack.imgur.com/OlAN6.pngMy manifest file doesn't contain anything out of the ordinary, and here is my event page code snippet:
function anyAlarmHandler (Alarm anyAlarm) {
// Simply clearing any alarm for now.
chrome.alarms.clear(anyAlarm);
}
chrome.alarms.onAlarm.addListener(anyAlarmHandler);
Despite this setup, the system notifications are not being cleared as expected.
It appears that I may be listening for the wrong event, as system notifications might not actually be classified as alarms. Unfortunately, the 'notifications' API does not provide any guidance on capturing notifications.
I have come across this question which discusses detecting notifications, but it doesn't address the following concerns:
- I want to detect notifications generated by the browser itself, not by another extension (if that distinction matters).
- I also need to be able to modify these notifications - change the text, close them, etc.
I attempted to use the provided code from the mentioned link to display a dialog box when a notification appears (as a test), but even that method didn't work. I am hoping that I am overlooking some specific method or event listener within an API that would serve this purpose, but so far, my search has been unsuccessful. Any assistance would be greatly appreciated.