Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to display desktop notifications even when Chrome or Firefox is closed?

We're developing a website which sends push notifications to end users using GCM. We've gone through Service Worker and all. We have developed a prototype using this codelab tutorial. It is working so far, but the only issue is the notifications are displayed only when Chrome is opened. When Chrome is closed, the notifications don't reach the users.

I want to know is there any way we can overcome this and display the notifications even when the browser is closed, similar to Safari Push Notification. Thanks in advance!

like image 724
Sivaprasanna Sethuraman Avatar asked Feb 10 '16 09:02

Sivaprasanna Sethuraman


People also ask

Do browser notifications work when app is closed?

The Android OS is designed to listen for push messages and upon receiving one, wake up the appropriate Android app to handle the push message, regardless of whether the app is closed or not.


2 Answers

In Chrome. Only those users that happen to have an extension installed that requires background mode, like hangouts, will be able to receive push notifications when chrome is not "running". It does not seem like a good idea to rely on it.

The chrome team seems to be considering it for web push too but so far there is no ETA.

https://code.google.com/p/chromium/issues/detail?id=402456

like image 33
Miguel Garcia Avatar answered Oct 26 '22 18:10

Miguel Garcia


If you have a "background" permission in manifest.json, your background page will be able to show notifications even when Chrome window is closed.

"permissions": [
    "background"
],

As stated in the documentation:

When any installed hosted app, packaged app, or extension has "background" permission, Chrome runs (invisibly) as soon as the user logs into their computer—before the user launches Chrome. The "background" permission also makes Chrome continue running (even after its last window is closed) until the user explicitly quits Chrome.

You need to use the "background" permission with a background page, event page or a background window for hosted apps.

For web, use Push API for Chrome and other browsers. The advantage of using push messages is that even if your page is closed, your service worker will be woken up and be able to show a notification. Web Sockets and EventSource have their connection closed when the page or browser is closed so it's not recommended. Here is the documentation and example.

like image 121
abielita Avatar answered Oct 26 '22 17:10

abielita