[GH-ISSUE #199] Web Push support #157

Closed
opened 2026-05-05 03:51:04 -06:00 by gitea-mirror · 28 comments
Owner

Originally created by @ross-rosario on GitHub (Apr 6, 2022).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/199

This is a very neat tool. It's however missing a single feature that would make it a complete alternative for AWS/Azure notification solutions, and that is Push API support https://developer.mozilla.org/en-US/docs/Web/API/Push_API.

Any plans on enabling the server to push events to web clients? The goal is to get around the current limitation of the UI client, that needs to remain open to receive events.

Originally created by @ross-rosario on GitHub (Apr 6, 2022). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/199 This is a very neat tool. It's however missing a single feature that would make it a complete alternative for AWS/Azure notification solutions, and that is Push API support https://developer.mozilla.org/en-US/docs/Web/API/Push_API. Any plans on enabling the server to push events to web clients? The goal is to get around the current limitation of the UI client, that needs to remain open to receive events.
gitea-mirror 2026-05-05 03:51:04 -06:00
Author
Owner

@binwiederhier commented on GitHub (Apr 6, 2022):

I like the idea, and I vaguely remember looking into this a while ago. I don't quite know why I didn't pursue it further. I'll investigate it eventually.

<!-- gh-comment-id:1090707810 --> @binwiederhier commented on GitHub (Apr 6, 2022): I like the idea, and I vaguely remember looking into this a while ago. I don't quite know why I didn't pursue it further. I'll investigate it eventually.
Author
Owner

@binwiederhier commented on GitHub (Apr 6, 2022):

current limitation of the UI client, that needs to remain open to receive events.

To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such.

220406 15-50-42 Selection 001

<!-- gh-comment-id:1090709767 --> @binwiederhier commented on GitHub (Apr 6, 2022): > current limitation of the UI client, that needs to remain open to receive events. To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such. ![220406 15-50-42 Selection 001](https://user-images.githubusercontent.com/664597/162059186-56e670ae-212f-4a07-9cec-ba20a94be87b.png)
Author
Owner

@ross-rosario commented on GitHub (Apr 6, 2022):

To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such.

With Gmail and Whatsapp, you can receive a desktop notification (think the upper-right corner Mac OS bubble), and once clicked, the website will open in a browser tab. At least that's the behavior I'm currently pursuing.

@binwiederhier would you please provide some pointers on where such a feature could be plugged in the Ntfy codebase? is there any example I could follow? Thanks!

<!-- gh-comment-id:1090822911 --> @ross-rosario commented on GitHub (Apr 6, 2022): > To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such. With Gmail and Whatsapp, you can receive a desktop notification (think the upper-right corner Mac OS bubble), and once clicked, the website will open in a browser tab. At least that's the behavior I'm currently pursuing. @binwiederhier would you please provide some pointers on where such a feature could be plugged in the Ntfy codebase? is there any example I could follow? Thanks!
Author
Owner

@ross-rosario commented on GitHub (Apr 6, 2022):

Basically what I'm aiming to accomplish, is sending notifications to browsers, even when the website is closed, and only to the browsers that have subscribed to a certain topic. ie pubsub + Notifications API (which ntfy excels at) + Push API instead of Web Sockets or HTTP Streams.

<!-- gh-comment-id:1090840484 --> @ross-rosario commented on GitHub (Apr 6, 2022): Basically what I'm aiming to accomplish, is sending notifications to browsers, even when the website is closed, and only to the browsers that have subscribed to a certain topic. ie pubsub + Notifications API (which ntfy excels at) + Push API _instead of_ Web Sockets or HTTP Streams.
Author
Owner

@binwiederhier commented on GitHub (Apr 6, 2022):

With Gmail and Whatsapp, you can receive a desktop notification (think the upper-right corner Mac OS bubble), and once clicked, the website will open in a browser tab. At least that's the behavior I'm currently pursuing.

I am on Ubuntu, so I can't verify that. Can you maybe post a screenshot?

would you please provide some pointers on where such a feature could be plugged in the Ntfy codebase? is there any example I could follow?

This is tricky. I don't know anything about the server side implementation for the Push API. I don't know if it's based on HTTP/WebSockets/grpc/etc. I tried to look for libraries, but there are no popular libraries for Go, and the Push API seems like a more or less abandoned (or at least not widely used) standard, at least that's what it seemed in my 2min research.

As for where to plug it in: https://github.com/binwiederhier/ntfy/blob/main/server/server.go#L185-L215 -- My assumption is that it's another server on a different port. I honestly don't know though, because I can't for the life of me find out what protocol it uses.

Basically what I'm aiming to accomplish, is sending notifications to browsers, even when the website is closed, and only to the browsers that have subscribed to a certain topic. ie pubsub + Notifications API (which ntfy excels at) + Push API instead of Web Sockets or HTTP Streams.

Yeah I understand :-D

<!-- gh-comment-id:1090919591 --> @binwiederhier commented on GitHub (Apr 6, 2022): > With Gmail and Whatsapp, you can receive a desktop notification (think the upper-right corner Mac OS bubble), and once clicked, the website will open in a browser tab. At least that's the behavior I'm currently pursuing. I am on Ubuntu, so I can't verify that. Can you maybe post a screenshot? > would you please provide some pointers on where such a feature could be plugged in the Ntfy codebase? is there any example I could follow? This is tricky. I don't know anything about the server side implementation for the Push API. I don't know if it's based on HTTP/WebSockets/grpc/etc. I tried to look for libraries, but there are no popular libraries for Go, and the Push API seems like a more or less abandoned (or at least not widely used) standard, at least that's what it seemed in my 2min research. As for where to plug it in: https://github.com/binwiederhier/ntfy/blob/main/server/server.go#L185-L215 -- My assumption is that it's another server on a different port. I honestly don't know though, because I can't for the life of me find out what protocol it uses. > Basically what I'm aiming to accomplish, is sending notifications to browsers, even when the website is closed, and only to the browsers that have subscribed to a certain topic. ie pubsub + Notifications API (which ntfy excels at) + Push API instead of Web Sockets or HTTP Streams. Yeah I understand :-D
Author
Owner

@binwiederhier commented on GitHub (Apr 6, 2022):

Okay I read parts of the Web Push API spec, and it looks like I was wrong. Apparently the browsers provide a push service, so Firefox/Mozilla would provide https://updates.push.services.mozilla.com/wpush for instance, and the ntfy server would just have to forward the push to that.

So there is no additional server running that the browser has to connect to. It's all through Mozilla or Google's servers basically. I think in that case it's more similar to Firebase, in that we simply forward messages to the push service (see https://github.com/binwiederhier/ntfy/blob/main/server/server.go#L421). The crypto of the Web Push API is quite complex, which is why I really would want to use a library for it.

I think I may do this because it's fun. But I'm not guaranteeing any timelines.

<!-- gh-comment-id:1090929710 --> @binwiederhier commented on GitHub (Apr 6, 2022): Okay I read parts of the Web Push API spec, and it looks like I was wrong. Apparently the browsers provide a push service, so Firefox/Mozilla would provide `https://updates.push.services.mozilla.com/wpush` for instance, and the ntfy server would just have to forward the push to that. So there is no additional server running that the browser has to connect to. It's all through Mozilla or Google's servers basically. I think in that case it's more similar to Firebase, in that we simply forward messages to the push service (see https://github.com/binwiederhier/ntfy/blob/main/server/server.go#L421). The crypto of the Web Push API is quite complex, which is why I really would want to use a library for it. I think I may do this because it's fun. But I'm not guaranteeing any timelines.
Author
Owner

@karmanyaahm commented on GitHub (Apr 8, 2022):

https://github.com/SherClockHolmes/webpush-go/ is a pretty good and popular library for this. I think the main obstacle (iirc the last time I looked at the firebase code for ntfy), would be that right now, Firebase keeps track of which device is subscribed to which topic, whereas with WebPush, ntfy would have to keep track of endpoint->topic mappings.

Another advantage of implementing this would be that in addition to ntfy-over-firebase, ntfy-over-unifiedpush would become possible (since WebPush and UnifiedPush are compatible). Self-hosted servers could also have push using some gateways.

<!-- gh-comment-id:1092329335 --> @karmanyaahm commented on GitHub (Apr 8, 2022): https://github.com/SherClockHolmes/webpush-go/ is a pretty good and popular library for this. I think the main obstacle (iirc the last time I looked at the firebase code for ntfy), would be that right now, Firebase keeps track of which device is subscribed to which topic, whereas with WebPush, ntfy would have to keep track of endpoint->topic mappings. Another advantage of implementing this would be that in addition to ntfy-over-firebase, ntfy-over-unifiedpush would become possible (since WebPush and UnifiedPush are compatible). Self-hosted servers could also have push using some gateways.
Author
Owner

@sfkpmr commented on GitHub (Apr 29, 2022):

current limitation of the UI client, that needs to remain open to receive events.

To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such.

220406 15-50-42 Selection 001

Could you point me to how to do this? If I understand you correctly it'll keep me notified if something happens without needing a tab with ntfy open?

<!-- gh-comment-id:1113610972 --> @sfkpmr commented on GitHub (Apr 29, 2022): > > current limitation of the UI client, that needs to remain open to receive events. > > To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such. > > ![220406 15-50-42 Selection 001](https://user-images.githubusercontent.com/664597/162059186-56e670ae-212f-4a07-9cec-ba20a94be87b.png) Could you point me to how to do this? If I understand you correctly it'll keep me notified if something happens without needing a tab with ntfy open?
Author
Owner

@binwiederhier commented on GitHub (Apr 29, 2022):

Right click on the tab -> Pin tab

<!-- gh-comment-id:1113621420 --> @binwiederhier commented on GitHub (Apr 29, 2022): Right click on the tab -> Pin tab
Author
Owner

@binwiederhier commented on GitHub (Apr 29, 2022):

This does need the tab open though, but the tab is pinned, so it's just the small icon. There is no way to receive notifications without an open tab, unless you use the ntfy CLI: https://ntfy.sh/docs/subscribe/cli/#subscribe-to-topics

<!-- gh-comment-id:1113624538 --> @binwiederhier commented on GitHub (Apr 29, 2022): This does need the tab open though, but the tab is pinned, so it's just the small icon. There is no way to receive notifications without an open tab, unless you use the ntfy CLI: https://ntfy.sh/docs/subscribe/cli/#subscribe-to-topics
Author
Owner

@sfkpmr commented on GitHub (Apr 29, 2022):

Gotcha, hopefully push can help with it.

<!-- gh-comment-id:1113645151 --> @sfkpmr commented on GitHub (Apr 29, 2022): Gotcha, hopefully push can help with it.
Author
Owner

@mmojadad commented on GitHub (Feb 5, 2023):

VAPID, which stands for Voluntary Application Server Identity, is a new way to send and receive website push notifications. Your VAPID keys allow you to send web push campaigns without having to send them through a service like Firebase Cloud Messaging (or FCM)

<!-- gh-comment-id:1416882850 --> @mmojadad commented on GitHub (Feb 5, 2023): VAPID, which stands for Voluntary Application Server Identity, is a new way to send and receive website push notifications. Your VAPID keys allow you to send web push campaigns without having to send them through a service like Firebase Cloud Messaging (or FCM)
Author
Owner

@pinpox commented on GitHub (May 26, 2023):

Any news on this? I looked into how this would be implemened but wasn't able to find any simple tutorials of how to do this in go. i've seen more and more web pages sending these notifications, any hints on how you would add this?
If it's not a huge task I might consider preparing a PR

<!-- gh-comment-id:1564374230 --> @pinpox commented on GitHub (May 26, 2023): Any news on this? I looked into how this would be implemened but wasn't able to find any simple tutorials of how to do this in go. i've seen more and more web pages sending these notifications, any hints on how you would add this? If it's not a huge task I might consider preparing a PR
Author
Owner

@nimbleghost commented on GitHub (May 26, 2023):

@pinpox I just started working on this in #751, there are still some open questions about the UX around subscribing to background notifications.

There's also some technical stuff left - handling syncing from accounts and handling re-subscribing if the subscription is broken for whatever reason, and more testing on iOS (notifications work, the PWA needs to be tested more).

<!-- gh-comment-id:1564758488 --> @nimbleghost commented on GitHub (May 26, 2023): @pinpox I just started working on this in #751, there are still some open questions about the UX around subscribing to background notifications. There's also some technical stuff left - handling syncing from accounts and handling re-subscribing if the subscription is broken for whatever reason, and more testing on iOS (notifications work, the PWA needs to be tested more).
Author
Owner

@icxes commented on GitHub (May 27, 2023):

I've been testing the web push from #751 for a bit now, and it's been working great for me and the few other people that use my server. I was hoping this feature would be implemented soon, so big thanks to you for your work on it @nimbleghost!

<!-- gh-comment-id:1565417001 --> @icxes commented on GitHub (May 27, 2023): I've been testing the web push from #751 for a bit now, and it's been working great for me and the few other people that use my server. I was hoping this feature would be implemented soon, so big thanks to you for your work on it @nimbleghost!
Author
Owner

@helmut72 commented on GitHub (May 29, 2023):

@nimbleghost
This would be fantastic if it works on iOS. How can I create a Docker image with your patch?

<!-- gh-comment-id:1566765881 --> @helmut72 commented on GitHub (May 29, 2023): @nimbleghost This would be fantastic if it works on iOS. How can I create a Docker image with your patch?
Author
Owner

@nimbleghost commented on GitHub (May 29, 2023):

@helmut72 I also added #754, so you can simply checkout the branch run it from there.

e.g. locally: https://docs.ntfy.sh/develop/#build-a-docker-image-only-for-linux

or if using it in a compose file:

  ntfy:
    build:
      context: ../path-to-checked-out-ntfy/
      dockerfile: Dockerfile-build
    command:
      - serve

Please be aware that it's a WIP and I've already changed the db schema without migrations since it isn't released yet, so if you run it you may have to delete your web-push-subscriptions-file database when pulling in updates. Service workers / application caching is also being worked on, which may result in odd behaviour and need a manual unregistration if something breaks (though so far hasn't been a problem).

<!-- gh-comment-id:1566783122 --> @nimbleghost commented on GitHub (May 29, 2023): @helmut72 I also added #754, so you can simply checkout the branch run it from there. e.g. locally: https://docs.ntfy.sh/develop/#build-a-docker-image-only-for-linux or if using it in a compose file: ```yaml ntfy: build: context: ../path-to-checked-out-ntfy/ dockerfile: Dockerfile-build command: - serve ``` Please be aware that it's a WIP and I've already changed the db schema without migrations since it isn't released yet, so if you run it you may have to delete your `web-push-subscriptions-file` database when pulling in updates. Service workers / application caching is also being worked on, which may result in odd behaviour and need a manual unregistration if something breaks (though so far hasn't been a problem).
Author
Owner

@helmut72 commented on GitHub (May 29, 2023):

@nimbleghost thanks, I have just used your repo:
https://github.com/nimbleghost/ntfy

But webpush doesn't work. Added my webapp to home screen, check if notifications are enabled for this webapp, but I see the message "notification won't be supported"

<!-- gh-comment-id:1566846752 --> @helmut72 commented on GitHub (May 29, 2023): @nimbleghost thanks, I have just used your repo: https://github.com/nimbleghost/ntfy But webpush doesn't work. Added my webapp to home screen, check if notifications are enabled for this webapp, but I see the message "notification won't be supported"
Author
Owner

@nimbleghost commented on GitHub (May 29, 2023):

@helmut72 are you using the correct branch? It's this one: https://github.com/nimbleghost/ntfy/tree/pwa

but if you are you also need to be serving the web app over https, and have the right config values set (see https://github.com/nimbleghost/ntfy/blob/pwa/docs/config.md#config-options and look for the web push options)

<!-- gh-comment-id:1566868487 --> @nimbleghost commented on GitHub (May 29, 2023): @helmut72 are you using the correct branch? It's this one: https://github.com/nimbleghost/ntfy/tree/pwa but if you are you also need to be serving the web app over https, and have the right config values set (see https://github.com/nimbleghost/ntfy/blob/pwa/docs/config.md#config-options and look for the web push options)
Author
Owner

@helmut72 commented on GitHub (May 29, 2023):

@nimbleghost Thanks, I've overseen that required config options. Great, now it works. I just miss that sound/beep and in the notification menu, ntfy is there twice. One entry with, other without sound.

<!-- gh-comment-id:1567364531 --> @helmut72 commented on GitHub (May 29, 2023): @nimbleghost Thanks, I've overseen that required config options. Great, now it works. I just miss that sound/beep and in the notification menu, ntfy is there twice. One entry with, other without sound.
Author
Owner

@nimbleghost commented on GitHub (May 29, 2023):

@helmut72 Nice! Not sure which commit you have, but the latest changes should have both the sound and double notifications fixed. If the sound still doesn't work, can you check your browser console's error messages and tell me what browser you're testing with?

<!-- gh-comment-id:1567371002 --> @nimbleghost commented on GitHub (May 29, 2023): @helmut72 Nice! Not sure which commit you have, but the latest changes should have both the sound and double notifications fixed. If the sound still doesn't work, can you check your browser console's error messages and tell me what browser you're testing with?
Author
Owner

@mmojadad commented on GitHub (May 29, 2023):

I am interest to have such features on web push

  • Segments so subscribers choose their interests
  • Enable GPS location to collect the subscribers GPS locations
  • Add dynamic fields to collect any user's information
  • Localize the subscription page and popup / Design and build your own subscription page ( short code, etc... )
  • Different popup designs, layouts and positions
  • Display offline messages
  • campaign builder
<!-- gh-comment-id:1567405149 --> @mmojadad commented on GitHub (May 29, 2023): I am interest to have such features on web push - Segments so subscribers choose their interests - Enable GPS location to collect the subscribers GPS locations - Add dynamic fields to collect any user's information - Localize the subscription page and popup / Design and build your own subscription page ( short code, etc... ) - Different popup designs, layouts and positions - Display offline messages - campaign builder
Author
Owner

@binwiederhier commented on GitHub (May 29, 2023):

@mmojadad you've got the wrong tool here. ntfy is a privacy focused push notification service. Not a marketing platform. We will not add features to collect gps data or any user data, or support for campaigns.

<!-- gh-comment-id:1567414886 --> @binwiederhier commented on GitHub (May 29, 2023): @mmojadad you've got the wrong tool here. ntfy is a privacy focused push notification service. Not a marketing platform. We will not add features to collect gps data or any user data, or support for campaigns.
Author
Owner

@mmojadad commented on GitHub (May 29, 2023):

@ binwiederhier Thanks for your clearifications.

<!-- gh-comment-id:1567416943 --> @mmojadad commented on GitHub (May 29, 2023): @ binwiederhier Thanks for your clearifications.
Author
Owner

@helmut72 commented on GitHub (May 29, 2023):

@helmut72 Nice! Not sure which commit you have, but the latest changes should have both the sound and double notifications fixed. If the sound still doesn't work, can you check your browser console's error messages and tell me what browser you're testing with?

I have played with a commit from today lunch time. Now I've build it about 30min ago. Deleted everything and ntfy isn't there twice in the notification settings. In this single setting there is now no sound entry:

ntfy1

From the menu in the ntfy webapp, where I can choose the sound, sound now plays on my iPhone (and iPad):

ntfy2

But this feels more like a very small sound stream (like from Youtube) and not like a notification sound, because it's also there in the global player of iOS:

ntfy3

<!-- gh-comment-id:1567442553 --> @helmut72 commented on GitHub (May 29, 2023): > @helmut72 Nice! Not sure which commit you have, but the latest changes should have both the sound and double notifications fixed. If the sound still doesn't work, can you check your browser console's error messages and tell me what browser you're testing with? I have played with a commit from today lunch time. Now I've build it about 30min ago. Deleted everything and ntfy isn't there twice in the notification settings. In this single setting there is now no sound entry: ![ntfy1](https://github.com/binwiederhier/ntfy/assets/1388751/f940ee18-fee8-4113-aabb-3400165145d9) From the menu in the ntfy webapp, where I can choose the sound, sound now plays on my iPhone (and iPad): ![ntfy2](https://github.com/binwiederhier/ntfy/assets/1388751/7b9d22a5-47e2-4b7c-a610-77ad109abe3b) But this feels more like a very small sound stream (like from Youtube) and not like a notification sound, because it's also there in the global player of iOS: ![ntfy3](https://github.com/binwiederhier/ntfy/assets/1388751/84704e47-741f-4869-a182-6240c397889e)
Author
Owner

@nimbleghost commented on GitHub (May 29, 2023):

@helmut72 Ah you meant for the notification - as far as I can see iOS doesn't support sounds for web push whatsoever at the moment.

<!-- gh-comment-id:1567446257 --> @nimbleghost commented on GitHub (May 29, 2023): @helmut72 Ah you meant for the notification - as far as I can see iOS doesn't support sounds for web push whatsoever at the moment.
Author
Owner

@helmut72 commented on GitHub (May 29, 2023):

@nimbleghost Ok, I was unaware of this. Thanks for the info. Then it looks good for me.

<!-- gh-comment-id:1567451425 --> @helmut72 commented on GitHub (May 29, 2023): @nimbleghost Ok, I was unaware of this. Thanks for the info. Then it looks good for me.
Author
Owner

@binwiederhier commented on GitHub (Jun 1, 2023):

I am closing this in favor of #346, which is (essentially) a duplicate. @nimbleghost is working on this right now.

<!-- gh-comment-id:1572576267 --> @binwiederhier commented on GitHub (Jun 1, 2023): I am closing this in favor of #346, which is (essentially) a duplicate. @nimbleghost is working on this right now.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/ntfy#157
No description provided.