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

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!

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.

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

Showing notification when the browser or tab is closed requires the service worker and a third party service (like google firebase)to trigger the service worker.
https://github.com/web-push-libs/ - Check these list of libraries to implement this in different platforms.
https://github.com/rijoshrc/php-service-worker-push-notification - Clone this git repository to see the simple implementation in PHP.

Related

Blazor WASM PWA: Google Chrome does not show Push Notifications

I've just tested Blazor example Blazing Pizza that uses push notifications as a PWA feature on Blazor. I changed public/private keys with my own generated ones and ran the project with MS Edge browser and push notifications worked as desired. But when I open it with Google Chrome, it doesn't shows any notification! (I allowed to show notifications).
I traced service-worker.js and found that notification hits the breakpoint, it means notification receives by browser but not showing:
I checked my Chrome's settings but not found anything to change.
I've found my mistake: I had blocked Google Chrome notifications in my Windows 10 notification settings!

Getting push notifications to launch Chrome on desktop windows when not running

Would appreciated help on a gap in comprehension. Sending push notifications to Chrome running on a Windows 10 machine (tried on older Windows also) results in the notifications popping up only when the Chrome browser is open (similarly for installing the page as a PWA). On numerous sites and posts it says that Chrome can run a background process even when the browser is closed and still receive notifications that will kick off the browser or the PWA.
Have reviewed a number of posts from back in 2015/2016 which don't appear relevant based on current state of service workers, PWAs. Have also looked at the W3C spec and Chromium post on design and architecture which don't really seem to cover how the host OS (e.g., Windows) invokes the browser.
The Chrome browser is set to run in the background (setting->advanced->Continue running background apps when Google Chrome is closed) but on closing Chrome and looking at the running processes on the system, there does not seem to a Chrome background thread running (i.e., it does not seem that Chrome inherently runs some background process). Push notifications (e.g., sent via OneSignal) which result in the appropriate page being opened when Chrome is already open or the PWA receiving the notification (we are currently using GCM not FCM if that makes a difference) if it is open, do not seem to kick off the chrome browser if it is not already running. Otherwise the notifications are processed correctly.
From the google developer site and OneSignal documentation, etc, I had somewhat assumed (apparently incorrectly) that having a service worker for push notification would somehow create a background process environment.
So, the question is, what is required to keep Chrome running in the background to be able to receive the push notifications? Can it be done with a service worker? If the code is in a PWA is that different? Is a Chrome extension required? though having to create an extension would seem contrary to the point of creating the service workers and making the app a PWA.
I note also that it posts indicate that with Firefox this is not possible as Firefox completely exits on close with no background processes.
Any thoughts would be appreciated.

Get Firebase Web Notification Even Close Chrome

I am currently working on a video web application. We rely on notification to notify provider there is call in.
Firebase works well even when I close the tab. I found that if there is any chrome's thread running in background, I will get notification.
Is there any way that I can make a background thread active even the user click close button on chrome? how about chrome extension? does it approach the goal?
Firebase Cloud Messaging for web relies on a service worker to receive messages when the web app is not active/visible. This requires that Chrome is active.
If the user completely quits Chrome, all tabs, service workers and extensions are stopped. There is no way to still receive web push notifications in that case.

How to start a background task when chrome fires up for a chrome app?

I am creating a chrome app (packaged) and I have to create a socket and listen for the incoming broadcast messages as soon as chrome browser starts up.
I came across this API , but it seems to be only for extensions.
And also the API for listening when a window is created needs the permission
"permissions": ["tabs"], and this also is available only for extensions.
So is this possible for a chrome app?
Thanks in advance.
chrome.runtime.onStartup is also available to the Chrome Apps (it is listed as supported api on Chrome App Platform API page). So you can just use it in your chrome app.
Chrome Apps also have an onStartup event, as documented here.
Additionally, you will likely want to handle events like onInstalled to start your background socket tcpServer after the app is first installed (or updated).
The "tabs" permission is only available to extensions, since apps are not meant to interact with the browser/webpages at all, so you certainly won't be able to use that.

Chrome apps that run on startup?

What would be the easiest way for me to set up a Chrome extension that starts when I log in to my Windows account, and can be connected to a WebSocket server to check for, say, new messages, and then pop open a desktop notification, that clicks to the messages web page?
I expect that making an extension is straight forward, as well as getting it to communicate with WebSockets, and making the desktop notification.
But what about making it automatically start when I log in to the computer? What would be a good way to do this in Windows? I am not interested in having the chrome browser to open up at log in, but I certainly don't mind if I see Chrome in the task bar.
You might look into chrome.runtime.onStartUp: https://developer.chrome.com/apps/runtime#event-onStartup, which is
"Fired when a profile that has this extension installed first starts up."
Also, you can use chrome.alarms to schedule a function to run every minute or so, to open a WebSocket somewhere, etc.
The app may try to unload itself if there are no active windows, so you can call some action in chrome.runtime.onSuspend (like loading an XHR somewhere) to cause onSuspendCanceled to trigger.