Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close/clear a chrome extension notification while notification panel is open

References: https://developer.chrome.com/apps/notifications

I am using the chrome.notifications.create(string id, object options, function callback); to create a chrome notification.

var id = 'list';

var options = {};
options.title = 'test';
options.iconUrl = 'notification_icon.png';
options.type = 'list';
options.message = "test";
options.buttons = [{title: 'test'}];
options.items = [{title: 'test', message:'test'}];

var createCallback = function(notificationId) { console.log(notificationId); };

chrome.notifications.create(id, options, createCallback); // returns 'list';

This creates a notification as expected. All working correctly.

I then call chrome.notification.clear(string id, function callback);

var id = 'list';

var clearCallback= function(wasCleared) { console.log(wasCleared); };

chrome.notification.clear(id, clearCallback); // returns true;

This does clear the notification. All working correctly.

EXCEPT it does not clear the notification out if the notification panel is open. This is not a major problem 99% of the time. Until I implemented the button code within the notification.

Using chrome.notifications.onButtonClicked.addListener(function callback); On click I am calling the clear notification panel code, and it reports back as it has been cleared.

var onButtonClickedCallback = function (notificationId, buttonIndex) {
    console.log(notificationId, buttonIndex);
    if ( notificationId == 'list' ) {
        chrome.notification.clear(id, clearCallback); // returns true;
    }
}
chrome.notifications.onButtonClicked.addListener(onButtonClickedCallback); // onClick it returns 'list', 0

But I am looking right at it.. Once the notification panel closes and opens again, I can confirm it has actually gone. But obviously since I am clicking a button on the notification, the panel is open, but it does not clear away as I would have liked.

All this is running in an extension background without the persistence: false property (so the script is always loaded, and since I can see the output, I know the functions are being called).

Have I overlooked something? I do not see any functions that deal with closing the notification panel. So as far as I can tell, I am clearing the notification but the panel is not updating it's display.

I am using Chrome 37.0.2019.0 canary on Win8

If anyone can suggest something I may have missed, I would be greatful. My google searches reveal people having problems with the HTML notification.

like image 598
WORMSS Avatar asked Mar 20 '23 11:03

WORMSS


1 Answers

This is a known bug, or rather an old design decision, with little progress.

Star the issue to raise its priority. I also suffer from the same.

like image 163
Xan Avatar answered Apr 26 '23 04:04

Xan