capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

Push notifications in PWA

Open no-1ne opened this issue 6 years ago • 22 comments
trafficstars

Folks thank you for capacitor.

Push notifications seem to be supported only in iOS and Android, but not Web, is there any reason for this? Web has notifications API

https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API

Kindly enlighten.

no-1ne avatar Mar 01 '19 07:03 no-1ne

If I would have to take a guess it is currently missing because of the required service worker. I guess a lot of projects already have a service worker. Our projects for example use the ngsw-worker from @angular/pwa, however, other projects may use totally different service workers so capacitor cannot assume if there is one and if so which one it is.

Like stated on https://capacitor.ionicframework.com/docs/basics/progressive-web-app/ writing service workers from scratch is complex. And "forcing" projects to use a certain one or even a new capacitor maintained service worker wouldn't be very good imho.

However, since I also would like to see Push Notification support for PWAs my suggestion would be to write a "smallest possible" service worker "extension", which only implements everything required for Push Notifications. Such a mini service worker could be included in the actual service worker file simply with importScripts('./capacitor-push-notifications-sw.js');. We have quite good experience with using just a 2 lines service worker "container" file which first imports the native Angular service worker and then our custom service worker. This method is agnostic to which "main" service worker is used and updates of the main service worker or its build process. But it would still require some manual setup (adding the importScripts and maybe registering they new "container" service worker). Still I think it could be worth it.

hsta avatar May 07 '19 18:05 hsta

Agreed, we need to figure out a good solution for service workers (likely what Ionic does: a basic implementation using workbox) and then add push support. Marking this as high priority.

mlynch avatar May 19 '19 15:05 mlynch

@mlynch Is there any branch currently that has development started on this task? I could probably help contribute to get this out sooner since I'm dealing with this now in an Ionic+Capacitor project.

CFT-Chris avatar Aug 13 '19 17:08 CFT-Chris

@mlynch @jcesarmobile, any chance this issue and the PR I submitted be discussed soon?

CFT-Chris avatar Dec 04 '19 16:12 CFT-Chris

Ionic team, please proceed as all tests passed and no conflicts.

jmdavid avatar Dec 16 '19 12:12 jmdavid

@mlynch Since this is still open, I am moving ahead using Workbox separate from Capacitor. In case this gets implemented, I hope the migration process would be smooth for me. Thanks.

tvvignesh avatar Dec 28 '19 15:12 tvvignesh

shouldn't this be as easy as using web-push package (and/or just SwPush) and VAPID / subscription management on the server side? https://blog.angular-university.io/angular-push-notifications/

side note - full integration with Firebase (like the need to create firebase project and wire it into the PWA) sounds to me like an unnecessary overkill in many cases

ciekawy avatar Aug 21 '20 20:08 ciekawy

Hi Capacitor team, Thanks for the great work. Any news on this topic ? Best,

dthib avatar May 06 '21 16:05 dthib

Any news?

reslear avatar Sep 01 '21 23:09 reslear

Hello, thanks everyone for the work on Capacitor. Just wondering whether this is coming soon?

spotvin42 avatar Feb 27 '22 02:02 spotvin42

If you use Angular, for now you can use their service worker package

StefanNedelchev avatar May 10 '22 18:05 StefanNedelchev

Most probably know already, but Web Push Notifications is coming to Safari (both iOS and macOS).

https://webkit.org/blog/12824/news-from-wwdc-webkit-features-in-safari-16-beta/#web-push-for-macos

(I don't know how that would work in a webview app wrapped within a native shell though, which is how most Capacitor apps are packaged on iOS)

sandstrom avatar Jul 28 '22 16:07 sandstrom

Most probably know already, but Web Push Notifications is coming to Safari (both iOS and macOS).

https://webkit.org/blog/12824/news-from-wwdc-webkit-features-in-safari-16-beta/#web-push-for-macos

(I don't know how that would work in a webview app wrapped within a native shell though, which is how most Capacitor apps are packaged on iOS)

They have already been available for macOS (I've even implemented them in 2019), it's just a bit different. It's only iOS where they haven't been available.

StefanNedelchev avatar Jul 31 '22 08:07 StefanNedelchev

It's now available for iOS too: https://webkit.org/blog/13878/web-push-for-web-apps-on-ios-and-ipados/

Anyone know if this will change how Capacitor-based apps (webviews) use Push Notifications? Or if that will stay the same?

sandstrom avatar Feb 17 '23 08:02 sandstrom

+1, I want to use it in Ionic as all the other components!

strarsis avatar Mar 21 '23 22:03 strarsis

iOS/iPad OS/macOS Safari support for browser push notifications finally rolled out with 16.4! 🍾

strarsis avatar Apr 01 '23 16:04 strarsis

but ok, already work with https://github.com/capawesome-team/capacitor-firebase/tree/main/packages/messaging

reslear avatar Apr 01 '23 19:04 reslear

Is there a way to utilize web push with Capacitor today? It feels suboptimal to require two push implementations (Web Push for PWA and Firebase for Capacitor in the same code base). If I understand correctly it seems to be possible to use Firebase for all platforms with the capawesome-team/capacitor-firebase package?

khromov avatar Apr 05 '23 23:04 khromov