【发布时间】:2012-11-24 10:19:23
【问题描述】:
我是 Chrome 扩展程序开发的新手。我编写了一个扩展程序,每次创建新选项卡时都会显示通知。它可以工作,但是如果我打开一个选项卡并立即打开另一个选项卡,通知将只显示第一个选项卡。
在Chrome extension documentation我读到这个:
一旦事件页面空闲了一小段时间(几秒钟),就会调度 chrome.runtime.onSuspend 事件。
显然它解释了为什么第二个标签没有通知。是否可以立即卸载事件页面(即显示通知后),而无需等待几秒钟?
这是我的代码:
manifest.json
{
"name": "test",
"version": "1.0",
"description": "notification test",
"manifest_version": 2,
"permissions": [ "tabs", "notifications" ],
"background": { "scripts": ["background.js"], "persistent": false }
}
background.js
var notification = webkitNotifications.createNotification(
'48.png',
'hello',
'this is a test'
);
chrome.tabs.onCreated.addListener(function(tab) {
notification.show();
});
【问题讨论】: