Chrome Notifications not appearing from Chrome Extension background page
You may have chrome notifications blocked. A good hint this is the case is if you aren't being constantly spammed with notifications from other websites. This answer worked for me.
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
Unfortunately detailed error messages for chrome.notifications have been suppressed from the console due to a bug that I haven't yet diagnosed; the reason your notification isn't being displayed is that it doesn't provide a required "iconUrl" parameter. When I tried the following in the background page of an extension I have installed:
var opt = {
iconUrl: "http://www.google.com/favicon.ico",
type: 'list',
title: 'Primary Title',
message: 'Primary message to display',
priority: 1,
items: [{ title: 'Item1', message: 'This is item 1.'},
{ title: 'Item2', message: 'This is item 2.'},
{ title: 'Item3', message: 'This is item 3.'}]
};
chrome.notifications.create('notify1', opt, function() { console.log('created!'); });
the notification is created successfully. It pays to check chrome.runtime.lastError:
var opt = {
type: 'list',
title: 'Primary Title',
message: 'Primary message to display',
priority: 1,
items: [{ title: 'Item1', message: 'This is item 1.'},
{ title: 'Item2', message: 'This is item 2.'},
{ title: 'Item3', message: 'This is item 3.'}]
};
chrome.notifications.create('notify1', opt, function(id) { console.log("Last error:", chrome.runtime.lastError); });
which would have shown you that in fact there are required properties and one is missing.
In my case, Chrome would show notification only once for a particular name/id being passed. As a workaround, I suffixed the name with current DateTime to make it unique.
chrome.notifications.create(`my-notification-${Date.now()}`, {
type: "basic",
iconUrl: "icons/logo.png",
title: "My Title",
message: "My Message",
});