1

I have a simple call to the chrome.notifications.create(id,options) function and I have checked the arguments ten times already.

The id argument is a string. The options argument is an object like this:

{type:"basic",message:"message",title:"message",iconUrl:chrome.extension.getURL("icons/icon.png")}

It is only working in Firefox though. Edge Opera and Chrome all fail to display the notification. Edge just crashes!

I've checked everything. There are no errors and the iconUrl is correct.

Also I checked the name field of the manifest json. It's fine. (Microsoft Edge notification in an extension)

Sample relevant and simplified code

This simplified version has the same problem as the complete one.

 //For hooking up event handlers
        try {
            chrome.runtime.onStartup.addListener(doHandshake);
        }catch(ex) {
            console.error("onStartup function in Edge is not supported.");
       }
    chrome.webRequest.onBeforeRequest.addListener(onBeforeRequestCallback, { types:['main_frame'],urls:['*://*/*']}, ['blocking']);

    function onBeforeRequestCallback(requestDetails) {
        showMessage();
        return {};
    }

    function showMessage() {
        console.log("about to show notification...");
        var notificationOptions ={type:"basic",message:"msg",title:"title",iconUrl:chrome.extension.getURL("icons/icon.png")};          
        chrome.notifications.create("",notificationOptions);    
    }

The manifest.json

{
  "manifest_version": 2,
  "author" : "whatever Ltd.",
  "name": "21charsName",
  "version": "1.0",
  "description": "whatever",
  "permissions": [
    "*://*/*",
    "tabs",
    "webRequest",
    "webRequestBlocking",
    "storage",
    "notifications"
  ],
  "browser_action": {
    "default_icon": "icons/icon.png",
    "default_title": "extension"
  },

  "background": {
    "scripts": [      
      "background.js"
    ],
    "persistent": true
  },
  "web_accessible_resources": []
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
Meghdad
  • 171
  • 1
  • 10

2 Answers2

1

It turned out that it's a bug in chromium-based browsers. It seems once you disable notifications for an extension it never ever show s notifications again because there's no way to re-enable it, and you'll have to reinstall the browser, though my attempt at that yielded nothing either.

I had to try on another machine with a brand new Chrome installation and the notifications started showing on that machine.

As for Edge, it turned out to be a bug too. :-/

Meghdad
  • 171
  • 1
  • 10
  • From your last post, I can see that you had posted the answer for the question. I suggest you to mark your own post as an accepted answer for this question after 24 hrs, when it is available to mark. It can help other community members in future in similar kind of questions. Thanks for your understanding. – Deepak-MSFT Mar 06 '19 at 02:32
1

If you are using Mac and Chrome 59+, it might be because the MacOS native notification is disabled for Chrome. Here's two possible solutions:

Solution 1

Open Chrome > Go chrome://flags > Search Enable native notifications > Change it to Disabled > Relaunch Chrome

Solution 2

Go to MacOS System Preferences > Notifications > Turn on Notifications for Banners/Alerts as shown here (likely previously it's Off)

Notifications Setting Screenshot


Reference 1

Reference 2

Matt Ke
  • 3,599
  • 12
  • 30
  • 49
Bobby Chang Liu
  • 321
  • 2
  • 5