Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send notifications to Chrome when the website tab is closed?

I'm trying to understand how to send notifications using the browser when my website is closed.

I see that Facebook does it but I can't get how.

Any help is welcome.

like image 216
Fez Vrasta Avatar asked Dec 23 '15 13:12

Fez Vrasta


People also ask

Do Chrome notifications work when Chrome is closed?

if you allow it then you will get notifications, it doesn't care if your browser is closed or open, it gets the job done and passes the notifications to you. Google Chrome posts the notifications in the Windows 10's action center which is a nice tight integration with Windows OS.

Do push notifications work when browser is closed?

This means the browser can have no windows open, and you'll still receive the push message in your service worker, because the browser in running in the background. The only time a push won't be received is when the browser is completely closed, i.e. not running at all (no marking).


1 Answers

You are looking for the Push API:

The Push API gives web applications the ability to receive messages pushed to them from a server, whether or not the web app is in the foreground, or even currently loaded, on a user agent. This lets developers deliver asynchronous notifications and updates to users that opt in, resulting in better engagement with timely new content.

And the Notifications API:

The Notification interface of the Notifications API is used to configure and display desktop notifications to the user.

You must use these in combination with a Service Worker. From the Push API documentation:

For an app to receive push messages, it has to have an active service worker. When the service worker is active, it can subscribe to push notifications using PushManager.subscribe().

like image 50
sdgluck Avatar answered Sep 29 '22 19:09

sdgluck