Send desktop notifications in Chrome or Firefox from a closed web app?
Asked Answered
E

2

66

My goal is to send Gmail-style desktop notifications in Chrome or Firefox from a web app (let's call it X) that is NOT currently open in the browser, without requiring the user to install an app or extension. It's okay if the user needs to grant permission to receive notifications from X, and it's okay if the browser needs to be open for the notification to appear, as long as X doesn't need to be open in the browser. A solution that doesn't require any browser window to be open would also work.

I just spent the day digging into this, and so far I think I've learned:

  • Since OSX Mavericks, it has been possible to do this in Safari 7+ via Safari Push Notifications.
  • The Web Notifications API works in Chrome/Firefox, but requires the user's browser to be open to X.
  • Twitter sends similar web notifications without asking the user for permission first, but requires the user's browser to be open to Twitter.
  • There are lots of references to possible Growl implementations, but as far as I can tell, all of them require the user to install Growl and/or a Growl-enabled app to work.

I could be wrong about any of my statements above - I'd love to hear it! - and I'm open to any other solution too. Any ideas?

Thanks for reading.

Exhaust answered 1/12, 2014 at 3:18 Comment(0)
W
87

You can send push notifications even when your web page is not active using Service Workers, the Notification API for service workers and the push API for server-initiated notifications (or scheduled notifications).

As of June 2016, Service Workers are supported in Chrome, Firefox and Opera. See the status at https://jakearchibald.github.io/isserviceworkerready/

See the following links for related discussions, status of implementation and specifications.

Whelm answered 2/12, 2014 at 18:12 Comment(4)
All the status pages you linked to seem to point out that this feature is live on Chrome.Lanceolate
Good answer with lots of resources and reference materials but it's a bit overwhelming. Is there an example of registering a service worker, handling a HTTP push, and then showing a user a notification?Dorkus
@Dorkus The answer by collimarco links to some complete tutorials. If you don't mind relying on Google's servers/infrastructure, see developers.google.com/web/updates/2015/03/…Whelm
As stated in in the w3.org/TR/task-scheduler This specification is being republished as a Working Group Note as an indication that it not being progressed further as a Recommendation track document. That sentence is hard to understand but I guess it means it's not going to get implemented.Accipiter
P
0

You can do exactly what you are looking for using the W3C Push API.

If you want to build everything from scratch I suggest to start reading this tutorial by Google. It is for Chrome, but Firefox works in a very similar way.

However it's a lot of work and the "standard" is still evolving: I suggest that you use a service like Pushpad (I am the founder).

Pulchi answered 21/3, 2016 at 11:28 Comment(1)
Disclaimer: this guy is the CTO at Pushpad, which is a paid serviceEarthly

© 2022 - 2024 — McMap. All rights reserved.