mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-05-09 08:26:00 +02:00
[GH-ISSUE #346] Support Web Push + PWA, for background notifications #269
Labels
No labels
ai-generated
android-app
android-app
android-app
🪲 bug
build
build
dependencies
docs
enhancement
enhancement
🔥 HOT
in-progress 🏃
ios
prio:low
prio:low
pull-request
question
🔒 security
server
server
unified-push
web-app
website
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ntfy#269
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Mikaela on GitHub (Jun 28, 2022).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/346
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.
@wunter8 commented on GitHub (Jun 29, 2022):
I've thought about trying to make this work. I think it might solve #199, too
@WebKenth commented on GitHub (Jul 13, 2022):
Just thought i would leave my 2 cents
You can create a shortcut with chrome and have it opened as a separate window


This will give it a sorta PWA like feel, although it is still a chrome instance just running in a separate window
@MaximilianGaedig commented on GitHub (Aug 18, 2022):
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.
@liamstojanovic commented on GitHub (Nov 9, 2022):
Made progress in making the react web app fulfill install-ability requirements on the
pwa-background-pushbranch of my forked repo.No custom service workers are hooked up yet, nor have I managed to successfully install the PWA version so far.
Next steps...
@BuckarooBanzay commented on GitHub (Nov 11, 2022):
Where are you planning to store the subscriptions from the client? Those have to be somewhere on the backend side 🤔
@liamstojanovic commented on GitHub (Nov 15, 2022):
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
app/directory can be imported into the service worker. Additionally, all of the examples I have seen online for enabling push notifications to be delivered from the service worker seem to leverage PushManager / web push protocol. I do not know how to configure / incorporate this server logic into the existing web app code; plus, all the class instances inapp/will cease to run once the PWA is closed.@binwiederhier commented on GitHub (Nov 16, 2022):
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 :-))
@BuckarooBanzay commented on GitHub (Nov 16, 2022):
(background: i've done this before and switched from my own webpush-
spaghetty-app to ntfy, it is an awesome tool btw 😉 )For webpush to work you need to generate a keypair, the public key is for the frontend and the private key is backend-only.
You also need to save the
subscriptionsfrom the frontend in the backend (somewhere in a database usually)A subscription can be obtained by the
pushManagerin the browser.This is a rough overview how a
subscriptionis obtained on the frontend/browser side:A
subscriptionlooks like this:For the sending part in the backend you should really use a library, i can suggest this:
https://www.npmjs.com/package/web-push EDIT: sorry i was somewhere else my my headhttps://github.com/SherClockHolmes/webpush-goSent notifications arrive in the
service-worker.jsand get dispatched to the user here:Side-note: pwa != webpush, both can be developed independently
@karmanyaahm commented on GitHub (Nov 17, 2022):
PWAs and WebPush are related but separate. One does not require the other.
I agree with @BuckarooBanzay's comment. The frontend is simple, an extra JS file that handles push, notifies, and stores it into the indexed DB.
The backend could get complicated, however. First, you need a way to register. Perhaps
POST ntfy.sh/mytopic,topic2/pushwith the subscription:Then, ntfy needs to store
mytopic:subscription, topic2:subscriptionin the database.Just like there's a
sendToFirebasefunction, there will have to be asendToPushfunction. On every message,sendToPushwill look up the subscriptions associated with that topic, and then run the WebPush library on each of those.The library encrypts the payload and POSTs it to the endpoint.
Details:
keysisnull(POST raw notification to the server).Feel free to ping me if you need more info about any of this.
@pinpox commented on GitHub (Jun 26, 2023):
Any plans for when this will be released?
@binwiederhier commented on GitHub (Jun 26, 2023):
@gedw99 @pinpox You can help test it. It's deployed on
https://staging.ntfy.shhttps://staging.ntfy.sh/app -- Docs are here: https://docs.ntfy.sh/subscribe/pwa/We found some small issues, but nothing major. It's almost ready for prime time. The code is already in the
mainbranch.@nimbleghost commented on GitHub (Jun 26, 2023):
specifically here: https://staging.ntfy.sh/app :D
and the self-hosting config docs are here: https://docs.ntfy.sh/config/#web-push
@binwiederhier commented on GitHub (Jun 27, 2023):
📢 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. 👏