我已经开发了一个扩展,并使用Chrome API,它每隔20秒从后台脚本发送通知
manifest.json
{
"name": "Test",
"description": "Test",
"manifest_version": 2,
"version": "0.1",
"chrome_url_overrides" : {
"newtab": "register.html"
},
"background": {
"scripts": ["background.js"]
},
"permissions": ["idle", "tabs", "gcm", "storage", "notifications"],
"icons": { "128": "gcm_128.png" }
}
background.js //发送通知
function messageReceived(message) {
var messageString = '';
if(message) messageString = message;
var nid = getNotificationId();
messageString = messageString + nid;
// Pop up a notification to show the GCM message.
chrome.notifications.create(nid, {
title: 'Kukdu Kuuu',
iconUrl: 'gcm_128.png',
type: 'basic',
message: messageString
}, function() {});
}
// Returns a new notification ID used in the notification.
function getNotificationId() {
var id = Math.floor(Math.random() * 9007199254740992) + 1;
return id.toString();
}
setInterval(function() {
console.log('running - ');
messageReceived('test notification ');
}, 20000);
当我不在Chrome浏览器上时,它会显示一个通知,即当我不在焦点上时。但是当我在使用chrome时,我没有收到通知。
当我运行API,chrome.notifications.getAll()
时,我得到了整个I队列。
但是,通知不会立即显示在我的系统上。可能的问题是什么?然而,它在windows机器上运行得很好。
发布于 2017-06-16 21:23:08
这在chrome中是一个未解决的问题。
这是链接,
https://bugs.chromium.org/p/chromium/issues/detail?id=583746#
重要评论和总结,
这绝对是故意的,但这也是一个值得怀疑的决定。
优点:*不会通过通知中断电影等身临其境的内容。
缺点:人们使用全屏浏览也是一样的,尤其是。在Mac上使用新的全屏模式。
( dewittj@chromium.org发表评论)
和推送通知的当前行为,
It在全屏模式下对接收到的通知进行排队。
当用户退出全屏模式或切换到其他应用程序或窗口时,它会显示所有通知。
如果用户退出浏览器,则会在下次重新启动浏览器时显示通知。
https://stackoverflow.com/questions/44558715
复制相似问题