引用:https://developer.chrome.com/apps/notifications

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

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';

这将按预期创建通知。一切正常。

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

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

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

这确实清除了通知。所有工作正常。

除了以外,如果打开了通知面板,它不会清除通知。这不是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

但是,我正在查看它。.通知面板关闭并再次打开后,我可以确认它实际上已经消失了。但是很明显,由于我单击了通知上的按钮,因此面板处于打开状态,但是并没有像我希望的那样清除。

所有这些都在没有持久性的扩展后台中运行:false属性(因此始终加载脚本,并且由于我可以看到输出,因此知道正在调用函数)。

我忽略了什么吗?我看不到任何与关闭通知面板有关的功能。据我所知,我正在清除通知,但面板并未更新其显示。

我在Win8上使用Chrome 37.0.2019.0 canary

如果有人能建议我可能错过的事情,我将不胜感激。我的Google搜索表明人们在HTML通知方面遇到了问题。

最佳答案

这是known bug,或者说是较旧的设计决策,进展甚微。

为问题加注星标以提高其优先级。我也一样。

10-05 21:07
查看更多