-
-
Notifications
You must be signed in to change notification settings - Fork 836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Web Push + PWA, for background notifications #346
Comments
I've thought about trying to make this work. I think it might solve #199, too |
The browser asks me if I want to receive notifications, it works in the foreground but after closing the page it does not work anymore. Service workers need to be implemented. |
Made progress in making the react web app fulfill install-ability requirements on the No custom service workers are hooked up yet, nor have I managed to successfully install the PWA version so far.
|
Nice work !! |
Where are you planning to store the subscriptions from the client? Those have to be somewhere on the backend side 🤔 |
I've hit a blocker with this endeavor. I've made the web app install-able, and added appropriate views / preferences for enabling background notifications, but am lost when it comes to actually delivering notifications from the service worker itself, or how to go about listening for events that trigger a notification. None of the classes in the |
So I know nothing about PWA, but I looked at web push and the service worker stuff for a while (not sure if that's the same thing), and the more I looked, the more confused I got. It's been a while, so my memory is fuzzy, but luckily I can ping some experts, that can hopefully shed some light :-D Pretty please, @p1gp1g @karmanyaahm (sorry for pinging you on two tickets :-)) |
(background: i've done this before and switched from my own webpush- For webpush to work you need to generate a keypair, the public key is for the frontend and the private key is backend-only. This is a rough overview how a if (navigator.serviceWorker){
// service-worker registration (snippet below)
navigator.serviceWorker.register('service-worker.js');
// ready event
navigator.serviceWorker.ready
.then(function(registration){
return registration.pushManager.getSubscription()
.then(function(subscription){
if (subscription)
// already subscribed
return subscription;
// new subscription
// public key from the backend
return fetch("api/push/pubkey")
.then(function(res){ return res.text(); })
.then(function(vapidPublicKey){
return registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: vapidPublicKey
});
});
});
})
.then(function(subscription){
// TODO: store subscription object in the backend for later notification
});
} else {
//no push
} A {
"endpoint": "https://browser-dependent-url.com/xy",
"keys": {
"auth": "abcde--",
"p256dh": "efgh=="
} For the sending part in the backend you should really use a library, i can suggest this: Sent notifications arrive in the self.addEventListener('push', function(event){
var payload = event.data ? event.data.text() : null;
if (!payload)
return;
var data = JSON.parse(payload);
event.waitUntil(
self.registration.showNotification(data.label, {
body: data.text
})
);
}); Side-note: pwa != webpush, both can be developed independently |
for storage I would suggest nats. you can embed nats or run it as a separate service. Nats is 100% golang. |
PWAs and WebPush are related but separate. One does not require the other. The backend could get complicated, however. First, you need a way to register. Perhaps {"endpoint": "https://browser-dependent-url.com/xy", "keys": {"auth": "abcde==","p256dh": "efgh=="}} Then, ntfy needs to store Just like there's a The library encrypts the payload and POSTs it to the endpoint. Details:
Feel free to ping me if you need more info about any of this. |
Any plans for when this will be released? |
would be good with a example as setting this all up can be complex. |
@gedw99 @pinpox You can help test it. It's deployed on We found some small issues, but nothing major. It's almost ready for prime time. The code is already in the |
specifically here: https://staging.ntfy.sh/app :D and the self-hosting config docs are here: https://docs.ntfy.sh/config/#web-push |
📢 Request for testing: The next ntfy server release will contain a progressive web app (PWA) with Web Push support, which means you'll be able to install the ntfy web app on your desktop or phone similar to a native app (even iOS! 🥳), and get basic push notification support (without any battery drain). Installing the PWA gives ntfy web its own launcher (e.g. shortcut on Windows, app on macOS, launcher shortcut on Linux, home screen icon on iOS, and launcher icon on Android), a standalone window, push notifications, and an app badge with the unread notification count. The (hopefully) production ready version of the PWA is currently deployed on https://staging.ntfy.sh/app -- Install instructions with screenshots can be found in the docs (https://docs.ntfy.sh/subscribe/pwa/). Please report bugs or issues on Discord/Matrix/Lemmy. PLEASE HELP TEST Huuuuge thanks goes to @nimbleghost for developing this entire feature top to bottom. If you throw donations my way, I'll share them with him. He certainly deserves it for all this great work. 👏 |
Thanks. It works on iOS safari Just had to A2HS and then grant notifications in the menu of the app. |
I am not sure what running as progressive web app requires, but I understand they should be able to support receiving notifications in the background even without the tab/app open as long as browser is running.
I think currently at least webapp manifest is missing.
Somewhat unrelatedly, iOS is also receiving support for web push sometime next year, https://webventures.rejh.nl/blog/2022/06/25/the-biggest-thing-from-wwdc22/Update 2023-04-02: iOS 16.4 supports web push when the PWA has been added to the homescreen.
The text was updated successfully, but these errors were encountered: