Listeners not working for Chrome Rich Notification API ManifestV2- Chrome Extension

94 views Asked by At

I'm unable to enter into any of the listener functions for notifications API with manifest V2. I'm able to execute the callback function after Notification is displayed. Also I can see that the chrome.notifications.onClicked.addListener is present while using in debugging mode.

Here's my manifest.json file

{
  "name": "Learning",
  "manifest_version": 2,
  "version": "1.3",
  "description": "Notification Popup",
  "background": {
    "scripts": ["script.js"],
    "persistent" : false
  },
  "permissions": [
    "notifications"
  ],
  "content_security_policy": "script-src 'self' 'unsafe-eval' https://ajax.googleapis.com/; object-src 'self'"
}

script.js

var options = {
    type: "basic",
    title: "Someone just replied to your mail",
    message: "You have been hired in our company",
    iconUrl: "stackIcon.PNG"
}
chrome.notifications.create(options,function() {
    console.log('Notification Callback');
});

chrome.notifications.onClicked.addListener(function() { 
    console.log('notification Clicked');

});
chrome.notifications.onClosed.addListener(function() {
    console.log('notification Closed');
});
chrome.notifications.onButtonClicked.addListener(function() {
    console.log('notification Button Clicked');
});

chrome.runtime.onInstalled.addListener(function() {
    console.log('runtime onInstalled');
})

console.log results

Notification Callback
1

There are 1 answers

0
Mohamed Mansour On

This is an unfortunate bug in Chromium Extensions, https://crbug.com/1168477, it has been fixed in version 91 canary.