Notification OnClicked event not working

When the user clicks my notification, I want them Firefox to open a website on a new tab, but I can’t get the onClicked event listener for notifications to work. I’ve followed all of the MDN documentation and tried just adding a console logging line in the callback, but it doesn’t do anything. No error messages appear in the console.

Any ideas?

I tested the code below in Firefox 48.0.1, 49 beta and 50 dev (on Windows 10):

chrome.notifications.onClicked.addListener(id => console.log('click', id));
chrome.notifications.create({
    type: 'basic',
    title: `Hi!`,
    message: `Let's test this ...`,
    iconUrl: '/icon.png',
});

(and clicked the notification)

48: nothing happens
49: it works
50: it works

So you will have to wait another 5 Weeks for this to work on the release channel.

Ok. Here is a side question.
Are we not allowed to open a new window/tab using the notifications onclick? I’ve tried the window.open() code in Javascript, but it doesn’t work. The console just returns null.

I think you can’t use window.open from the background page, at least I remember something along those lines. I’d assume you can use https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/Windows/create for that.

1 Like

That is perfect! Exactly what I was looking for!
Thanks!