notification.create isn't creating any kind of notification

1,322 views
Skip to first unread message

Tyler Crews

unread,
Aug 7, 2021, 9:51:24 PM8/7/21
to Chromium Extensions
I want to create a kind of alert() popup since the alert method isn't supported by chrome. For my extension basically I just want to make it clear to the user that the extension is taking an action so that they don't get confused when it happens.

so I'm working with the notifications api, and I believe I've correctly implemented it, but I can't get any notifications to appear... can't really see anything in the documentation what they're supposed to look like though.

as a test run to get a notification to pop up I have this code: 
chrome.runtime.onInstalled.addListener(
    function () {
        chrome.notifications.getPermissionLevel(function (level) {
            console.log(level);
        })
        //checking for permission level, says permissions are granted

        let testNotify = { type: 'basic', iconUrl: 'tyFav48.png', title: 'Notification Test', message: 'testing one, two' };
        chrome.notifications.create('Test Notification', testNotify, function (notificationId) {
            console.log('did this work');
            console.log(notificationId);
        });
    });


on installation of the extension and checking the console I get:
>granted
>did this work
>Test Notification

as a side note I do already have notifications declared in my manifest permissions. I believe this is implicit because the console log in the notifications.create wouldn't run without it(?), but just to be clear.

so I'm getting a granted status, and I'm getting a console log from within the notification,
but I don't know what else I need to do from here. Have any of you had this problem?

If it's possible for you to attach a screencap, I'd love to see what the extension-created notifications even look like.

Thanks for your help!
-Tyler

Cuyler Stuwe

unread,
Aug 7, 2021, 9:54:15 PM8/7/21
to Tyler Crews, Chromium Extensions
Is this for V3? If so, I think I read something about Google doing away with the extension notification API in V3.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/25f6fe93-dd42-458b-9a09-e06028f8bcefn%40chromium.org.

Jackie Han

unread,
Aug 8, 2021, 1:22:42 AM8/8/21
to Tyler Crews, Chromium Extensions
Hi,

your code is correct.
1. don't suggest putting notifications in the onInstalled event.
2. Why doesn't it display? On macOS(I don't test on other OS), if all title,message,id of the notification are the same, the system only displays this notification at the first time. After you clear this notification in the system notification center, call it again, it can display.

--

Tyler Crews

unread,
Aug 8, 2021, 3:49:19 AM8/8/21
to Chromium Extensions, Jackie Han, Chromium Extensions, Tyler Crews
Thanks for the response, Jackie. 

1. For reference I also tested my code in an onCompleted event for navigating to a specific site (reddit). 

chrome.webNavigation.onCompleted.addListener(details => {

    let testNotify2 = {
        type: 'basic',
        message: 'this is a notification please notify the user of something',
        title: 'Notification Test',
        iconUrl: './tyFav48.png',
        priority: 1
    };
    chrome.notifications.create('Test Notification 2', testNotify2, function (notificationId) {
        console.log('did this work? it should have a notification up now');
        console.log(notificationId);
    });
    console.log('heard.');
}, {
    url: [{ hostContains: '.reddit' },]
});


2. That's a very good question, and is what I'm trying to figure out myself.
Attached are two screenshots of my devtools after navigating to reddit.
* the first shows that console logs are being sent for the string and notification ID properties within the notification creation.
* the second I THINK is my notification center in devtools? I'm not getting anything in there. Is there any way to display the system notification center anywhere else?

Jackie Han

unread,
Aug 8, 2021, 4:09:28 AM8/8/21
to Tyler Crews, Chromium Extensions
You forgot to attach the screenshots in your last message.
System Notification Center, I mean, is https://support.apple.com/en-us/HT204079

Message has been deleted

Tyler Crews

unread,
Aug 8, 2021, 4:53:24 AM8/8/21
to Chromium Extensions, Jackie Han, Chromium Extensions, Tyler Crews
oh yeah whoops. Okay no need to include those screenshots anymore luckily you've got me to the next step.
I'm on Windows 10, but I've figured out how to access the center now, 
windows users can use the shortcut [windows key]+a.

First off, if anyone in the future is having a similar issue, make sure you go to settings>system>notifications and actions and make sure that chrome is turned on. That was a big help for me lol.
(screenshot 1.)

Once I enabled chrome notifications to windows, I discovered two things:

1. some of my notifications are working correctly. 
(screenshot 2.)
Here the on-installed notification is shown. It correctly creates a little bubble and noise in the bottom right of the screen, and the console logs are shown in the dev tools correctly displaying once.

2. my onCompleted navigation notifications are not correctly working.
(screenshot 3.)
They're getting 'trapped' in the system notification center (gray column on the right side of my screen). They correctly populate in the center, but are not appearing as bubbles and have no noise.
What you warned in bold seems to be true, and on navigation the code is completing Twice, causing the second notification to silently occur and block the first one from bubbling in. 
Not sure why my code is executing twice on navigation.

So your suggestions have been a huge help. Thanks, Jackie.
Going to take a deeper look at my service worker and try to figure out why it's behaving this way.
3. on navigation notification is going to center but not popping up.png
2. on installation notification is popping up.png
1. notifications and actions.png

Tyler Crews

unread,
Aug 8, 2021, 5:10:31 AM8/8/21
to Chromium Extensions, Tyler Crews, Jackie Han, Chromium Extensions

sorry, but to clarify in case you come back to this thread

debugging attempts that I've tried already - 
1. Clearing out the onInstalled notification before navigating to the site and triggering the onComplete notification
2. removing the onInstalled notification code completely, the onComplete code still triggers twice and doesn't result in a notification
3. changing the onComplete trigger site from reddit to google. 
This one is really interesting because when I navigate to google the code takes longer to double send. The following results occur: 
screenshot 4 shows that after navigating to google onComplete creates a bubbled notification.
screenshot 5 shows that even though I only navigated to the site once, onComplete triggers a second time.
3b. If I clear the first notification before the second trigger occurs, I'll receive a second bubble notification. If I don't clear out the first notification the second will silently be held in the system notification center.

Interesting...
4. double.png
5. double part 2.png

Jackie Han

unread,
Aug 8, 2021, 5:26:32 AM8/8/21
to Tyler Crews, Chromium Extensions
Navigation events are too frequent.
chrome.notifications.create(notificationId, options, callback);
In real use cases, you should consider different id, title, content for different notifications.

Tyler Crews

unread,
Aug 8, 2021, 5:39:39 AM8/8/21
to Chromium Extensions, Jackie Han, Chromium Extensions, Tyler Crews
Yeah, that's fair. I'll be keeping them more distinct in the future.

Thanks again for your help!


I've managed to solve my double-navigation issue.
If anyone is reading this later here's what I did:

Luckily other people had an issue with chrome double-firing navigation commands as well. 
thanks to another answer on there I console logged the details object of my onCompleted function and noticed a trend that the second firing of the function always had a details.frameId of 0.
So I wrote an if statement to catch it if the onCompleted was firing for a second time like this:

chrome.webNavigation.onCompleted.addListener(details => {
    //need to make sure that this only triggers once per navigation
    console.log(details);
    if (details.frameId === 0) return;
});



Issue solved. Thanks all 💕

hrg...@gmail.com

unread,
Aug 8, 2021, 3:53:43 PM8/8/21
to Chromium Extensions, tycr...@gmail.com, Jackie Han, Chromium Extensions
This is a known issue with notifications in Windows 10.

Windows 10 notification center has its own rules and features, which don't match the rules and features of Chrome's notifications API.
For example, when you shown a notification with a progress bar, you need to update the progress amount after creating the notification. This should make the progress bar to advance.
Unfortunately, Windows 10 notification system is not designed to show this kind of progress notifications, so users never see the progress bar advancing.

Under Windows 7, Chrome uses its own notification mechanism, and so the notifications API works correctly.

paul deuana

unread,
Aug 9, 2021, 11:27:53 AM8/9/21
to Tyler Crews, Chromium Extensions


Cheers

From: chromium-...@chromium.org <chromium-...@chromium.org> on behalf of Tyler Crews <tycr...@gmail.com>
Sent: Sunday, August 8, 2021 9:51:24 AM
To: Chromium Extensions <chromium-...@chromium.org>
Subject: [crx] notification.create isn't creating any kind of notification
 
--
Reply all
Reply to author
Forward
0 new messages