在通知面板打开时关闭/清除chrome扩展通知

WOR*_*MSS 4 javascript notifications google-chrome google-chrome-extension

参考:https://developer.chrome.com/apps/notifications

我正在使用chrome.notifications.create(字符串id,对象选项,函数回调); 创建chrome通知.

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';
Run Code Online (Sandbox Code Playgroud)

这会按预期创建通知.一切正常.

然后我调用chrome.notification.clear(string id,function callback);

var id = 'list';

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

chrome.notification.clear(id, clearCallback); // returns true;
Run Code Online (Sandbox Code Playgroud)

这确实清除了通知.一切正常.

除非它不清除出通知,如果通知面板打开.这在99%的时间里都不是主要问题.直到我在通知中实现了按钮代码.

使用chrome.notifications.onButtonClicked.addListener(函数回调); 点击后,我正在调用清除通知面板代码,并在清除时报告.

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
Run Code Online (Sandbox Code Playgroud)

但我正在考虑它..一旦通知面板关闭并再次打开,我可以确认它已经真正消失了.但很明显,因为我点击通知上的按钮,面板是打开的,但它并没有像我希望的那样清除.

所有这些都在扩展后台运行而没有持久性:false属性(因此脚本总是被加载,因为我可以看到输出,我知道正在调用函数).

我忽略了什么吗?我没有看到任何与关闭通知面板有关的功能.所以据我所知,我正在清除通知,但面板没有更新它的显示.

我在Win8上使用Chrome 37.0.2019.0 canary

如果有人能提出我可能错过的东西,我会很高兴.我的谷歌搜索显示人们有HTML通知问题.

Xan*_*Xan 5

这是一个已知的错误,或者说是一个旧的设计决策,进展甚微.

明确问题以提高其优先级.我也遭受同样的痛苦.