Reputation: 1967
I have developed an extension and using Chrome API, which sends notification every 20 secs from background script
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 //sends notification
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);
It shows a notification when I am not on Chrome browser i.e when I am out of focus. But I don't receive notification when I am working on chrome.
When I run API, chrome.notifications.getAll()
, I get the entire queue of IDs.
But, notifications are not getting displayed immediately on my system. What could be the problem? However, it works well on the windows machine.
Upvotes: 0
Views: 521
Reputation: 1967
This is an open issue in chrome.
Here is the link,
https://bugs.chromium.org/p/chromium/issues/detail?id=583746#
Important comments & summary,
This is definitely intentional but is is also a questionable decision.
Pro: * Won't interrupt immersive content such as movies with a notification.
Con: * People use full screen to just browse as well, esp. on Mac with the new fullscreen mode.
( Comment by [email protected] )
And current behaviour of pushnotifications,
It queues received notification while in full-screen mode.
It shows all the notifications when user exits fullscreen mode or switch to some other app or window.
If the user exits the browser, the notifications is displayed on next browser restart.
Upvotes: 1