Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

FòrumCAT

  1. Home
  2. NodeBB Development
  3. Native Push Notifications Support for NodeBB

Native Push Notifications Support for NodeBB

Scheduled Pinned Locked Moved NodeBB Development
pushnotificationodebbnotificationspushapi
50 Posts 9 Posters 1 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J julian@community.nodebb.org
    12 Sept 2024, 03:49

    phenomlab clearing the browser cache wouldn't actually remove the service worker, unfortunately.

    It's proving surprisingly hard to find instructions to teach people how to clear the existing service worker 😝

    Chrome, at least, will check for a new one after 24 hours I think .

    P This user is from outside of this forum
    P This user is from outside of this forum
    phenomlab@community.nodebb.org
    wrote on 12 Sept 2024, 10:36 last edited by
    #8

    julian OK. Still no activity for me though despite updates here. Did you also remove ntfy as that isn't issuing alerts anymore.

    A bit greedy, but this js would probably work

    if ('serviceWorker' in navigator) {
      caches.keys().then(function(cacheNames) {
        cacheNames.forEach(function(cacheName) {
          caches.delete(cacheName);
        });
      });
    }
    

    Or perhaps this header

    Cache-Control: no-cache,no-store,must-revalidate
    

    Or this modified js

    function async deleteCaches() {
      try {
        const keys = await window.caches.keys();
        await Promise.all(keys.map(key => caches.delete(key)));
      } catch (err) {
        console.log('deleteCache err: ', err);
      }
    }
    
    // run this function on your app load
    function resetCacheForUpdate() {
      if (!localStorage.getItem('cacheReset')) {
        deleteCaches()
          .then(_ => {
            localStorage.setItem('cacheReset', 'yes');
          }) 
      }
    }
    

    Source

    https://jun711.github.io/web/service-worker-cache-busting/

    J 1 Reply Last reply 12 Sept 2024, 13:54
    0
    • P phenomlab@community.nodebb.org
      12 Sept 2024, 10:36

      julian OK. Still no activity for me though despite updates here. Did you also remove ntfy as that isn't issuing alerts anymore.

      A bit greedy, but this js would probably work

      if ('serviceWorker' in navigator) {
        caches.keys().then(function(cacheNames) {
          cacheNames.forEach(function(cacheName) {
            caches.delete(cacheName);
          });
        });
      }
      

      Or perhaps this header

      Cache-Control: no-cache,no-store,must-revalidate
      

      Or this modified js

      function async deleteCaches() {
        try {
          const keys = await window.caches.keys();
          await Promise.all(keys.map(key => caches.delete(key)));
        } catch (err) {
          console.log('deleteCache err: ', err);
        }
      }
      
      // run this function on your app load
      function resetCacheForUpdate() {
        if (!localStorage.getItem('cacheReset')) {
          deleteCaches()
            .then(_ => {
              localStorage.setItem('cacheReset', 'yes');
            }) 
        }
      }
      

      Source

      https://jun711.github.io/web/service-worker-cache-busting/

      J This user is from outside of this forum
      J This user is from outside of this forum
      julian@community.nodebb.org
      wrote on 12 Sept 2024, 13:54 last edited by
      #9

      phenomlab It is not the service worker cache that is at fault, it's the fact that the service worker itself is outdated on your machine 😓

      But that will resolve over time, and I will look into further strategies.

      That said, twice already I've lost my subscription to the push service. Will have to dig into it and see what error is thrown.

      P 1 Reply Last reply 12 Sept 2024, 17:40
      0
      • J julian@community.nodebb.org
        12 Sept 2024, 13:54

        phenomlab It is not the service worker cache that is at fault, it's the fact that the service worker itself is outdated on your machine 😓

        But that will resolve over time, and I will look into further strategies.

        That said, twice already I've lost my subscription to the push service. Will have to dig into it and see what error is thrown.

        P This user is from outside of this forum
        P This user is from outside of this forum
        phenomlab@community.nodebb.org
        wrote on 12 Sept 2024, 17:40 last edited by
        #10

        julian understood. I now have this working on my phone at least.

        Edit - and it works perfectly. I get the notification, click it and it uses my already open browser session to display.

        J 1 Reply Last reply 12 Sept 2024, 19:59
        0
        • P phenomlab@community.nodebb.org
          12 Sept 2024, 17:40

          julian understood. I now have this working on my phone at least.

          Edit - and it works perfectly. I get the notification, click it and it uses my already open browser session to display.

          J This user is from outside of this forum
          J This user is from outside of this forum
          julian@community.nodebb.org
          wrote on 12 Sept 2024, 19:59 last edited by
          #11

          phenomlab Glad to hear it!

          I updated the service worker so that when it is sent to the browser, it indicates that it is to immediately replace the existing worker, so hopefully my changes should be reflected quicker.

          1 Reply Last reply
          0
          • J julian@community.nodebb.org
            11 Sept 2024, 19:15

            Our relationship with push notifications has been rather circuitous...

            1. First Andrew (psychobunny) tried plain desktop notifications via the Notification API (that's the desktop notifications plugin), but notification delivery stopped when you closed your browser.
            2. Then I wrote the PushBullet plugin, but they went from free to paid and that went out the window
            3. Around that time I wrote the Firebase plugin, which was a dead end because there was no iOS support.
            4. I then wrote the ntfy plugin, which works really well, but does rely on a freemium third-party service and app (written by @binwiederhier@discuss.ntfy.sh)

            Thanks to some recent discussion from crazycells and bh4-tech, I learned that the Push API had reached general availability across most modern browsers. In fact, this actually happened over a year ago, so compatibility should be even better.

            So I set about working on yet another push notifications plugin, hopefully for the last time, and this time using the native Push API on the client-side.

            To enable them, simply navigate over to the "Push Notifications" menu item in your user profile, and flip the switch.

            6da06989-f902-492b-866f-14c39b34a9ca-image.png

            So, let's dogfood! I de-activated the ntfy plugin on this site and activated the web-push plugin so you can try it out right now.

            The plugin is in the proof-of-concept phase, so there might (read: most definitely will be) issues. Please let me know any you find here.

            J This user is from outside of this forum
            J This user is from outside of this forum
            julian@community.nodebb.org
            wrote on 23 Sept 2024, 16:15 last edited by
            #12

            The web-push plugin has now been promoted in v4 beta to "bundled" status, with a corresponding demotion of the ntfy plugin.

            https://github.com/NodeBB/NodeBB/commit/aa060d31d130cd54d18cd8dc2f25ba7de58f4fea

            P J 2 Replies Last reply 23 Sept 2024, 16:40
            0
            • J julian@community.nodebb.org
              23 Sept 2024, 16:15

              The web-push plugin has now been promoted in v4 beta to "bundled" status, with a corresponding demotion of the ntfy plugin.

              https://github.com/NodeBB/NodeBB/commit/aa060d31d130cd54d18cd8dc2f25ba7de58f4fea

              P This user is from outside of this forum
              P This user is from outside of this forum
              phenomlab@community.nodebb.org
              wrote on 23 Sept 2024, 16:40 last edited by
              #13

              julian Is there a link where we can install the v4 beta version of this plugin? I'd love to test it out over on Sudonix.

              EDIT - NVM - I found the link..

              J 1 Reply Last reply 23 Sept 2024, 16:50
              0
              • P phenomlab@community.nodebb.org
                23 Sept 2024, 16:40

                julian Is there a link where we can install the v4 beta version of this plugin? I'd love to test it out over on Sudonix.

                EDIT - NVM - I found the link..

                J This user is from outside of this forum
                J This user is from outside of this forum
                julian@community.nodebb.org
                wrote on 23 Sept 2024, 16:50 last edited by
                #14

                phenomlab glad to hear you found it 😄

                For those interested in updating, you can just grab the latest commit from activitypub branch or perhaps the more the specific commit:

                git fetch
                git checkout activitypub    # if you're not already on activitypub branch
                git reset --hard 86f624f8172fb96fbd3c83683affd8814e8b5156`
                
                P 1 Reply Last reply 23 Sept 2024, 16:59
                0
                • J julian@community.nodebb.org
                  23 Sept 2024, 16:15

                  The web-push plugin has now been promoted in v4 beta to "bundled" status, with a corresponding demotion of the ntfy plugin.

                  https://github.com/NodeBB/NodeBB/commit/aa060d31d130cd54d18cd8dc2f25ba7de58f4fea

                  J This user is from outside of this forum
                  J This user is from outside of this forum
                  julian@community.nodebb.org
                  wrote on 23 Sept 2024, 16:52 last edited by
                  #15

                  The plugin also successfully removes notifications if they're no longer relevant (e.g. queued posts that have already been handled), and merges notification content just like it does in-app:

                  22b1cb96-3763-48e9-b890-3f8443ace075-image.png

                  J 1 Reply Last reply 25 Sept 2024, 16:44
                  0
                  • J julian@community.nodebb.org
                    23 Sept 2024, 16:50

                    phenomlab glad to hear you found it 😄

                    For those interested in updating, you can just grab the latest commit from activitypub branch or perhaps the more the specific commit:

                    git fetch
                    git checkout activitypub    # if you're not already on activitypub branch
                    git reset --hard 86f624f8172fb96fbd3c83683affd8814e8b5156`
                    
                    P This user is from outside of this forum
                    P This user is from outside of this forum
                    phenomlab@community.nodebb.org
                    wrote on 23 Sept 2024, 16:59 last edited by
                    #16

                    julian I'm using the GIT link you provided to install. Plugin installs fine, but cannot get it to send any notification - even on my mobile device which works fine for NodeBB?

                    J 1 Reply Last reply 23 Sept 2024, 17:04
                    0
                    • P phenomlab@community.nodebb.org
                      23 Sept 2024, 16:59

                      julian I'm using the GIT link you provided to install. Plugin installs fine, but cannot get it to send any notification - even on my mobile device which works fine for NodeBB?

                      J This user is from outside of this forum
                      J This user is from outside of this forum
                      julian@community.nodebb.org
                      wrote on 23 Sept 2024, 17:04 last edited by
                      #17

                      phenomlab There's not terribly much to configure, just make sure that when you start NodeBB, that you see the output info: [plugins/web-push] VAPID keys OK.

                      That's how the messages are encoded to be sent to the corresponding browser push endpoints.

                      Other than that make sure the user has toggled push notifications on in their settings and allowed notifications for the site.

                      On Windows, you have to specifically also allow your browser access to send notifications to the user.

                      P 1 Reply Last reply 23 Sept 2024, 17:54
                      0
                      • J julian@community.nodebb.org
                        23 Sept 2024, 17:04

                        phenomlab There's not terribly much to configure, just make sure that when you start NodeBB, that you see the output info: [plugins/web-push] VAPID keys OK.

                        That's how the messages are encoded to be sent to the corresponding browser push endpoints.

                        Other than that make sure the user has toggled push notifications on in their settings and allowed notifications for the site.

                        On Windows, you have to specifically also allow your browser access to send notifications to the user.

                        P This user is from outside of this forum
                        P This user is from outside of this forum
                        phenomlab@community.nodebb.org
                        wrote on 23 Sept 2024, 17:54 last edited by
                        #18

                        julian Yes, I've done that, but can't seem to make it work.

                        1 Reply Last reply
                        0
                        • J julian@community.nodebb.org
                          11 Sept 2024, 19:15

                          Our relationship with push notifications has been rather circuitous...

                          1. First Andrew (psychobunny) tried plain desktop notifications via the Notification API (that's the desktop notifications plugin), but notification delivery stopped when you closed your browser.
                          2. Then I wrote the PushBullet plugin, but they went from free to paid and that went out the window
                          3. Around that time I wrote the Firebase plugin, which was a dead end because there was no iOS support.
                          4. I then wrote the ntfy plugin, which works really well, but does rely on a freemium third-party service and app (written by @binwiederhier@discuss.ntfy.sh)

                          Thanks to some recent discussion from crazycells and bh4-tech, I learned that the Push API had reached general availability across most modern browsers. In fact, this actually happened over a year ago, so compatibility should be even better.

                          So I set about working on yet another push notifications plugin, hopefully for the last time, and this time using the native Push API on the client-side.

                          To enable them, simply navigate over to the "Push Notifications" menu item in your user profile, and flip the switch.

                          6da06989-f902-492b-866f-14c39b34a9ca-image.png

                          So, let's dogfood! I de-activated the ntfy plugin on this site and activated the web-push plugin so you can try it out right now.

                          The plugin is in the proof-of-concept phase, so there might (read: most definitely will be) issues. Please let me know any you find here.

                          baris@community.nodebb.orgB This user is from outside of this forum
                          baris@community.nodebb.orgB This user is from outside of this forum
                          baris@community.nodebb.org
                          wrote on 24 Sept 2024, 00:10 last edited by
                          #19

                          On windows you need to enable notifications in the OS settings, it wasn't working without that for me.

                          image.png

                          P 1 Reply Last reply 24 Sept 2024, 00:39
                          0
                          • baris@community.nodebb.orgB baris@community.nodebb.org
                            24 Sept 2024, 00:10

                            On windows you need to enable notifications in the OS settings, it wasn't working without that for me.

                            image.png

                            P This user is from outside of this forum
                            P This user is from outside of this forum
                            phenomlab@community.nodebb.org
                            wrote on 24 Sept 2024, 00:39 last edited by
                            #20

                            baris thanks. That setting is already on for me.

                            J 1 Reply Last reply 25 Sept 2024, 11:49
                            0
                            • P phenomlab@community.nodebb.org
                              24 Sept 2024, 00:39

                              baris thanks. That setting is already on for me.

                              J This user is from outside of this forum
                              J This user is from outside of this forum
                              julian@community.nodebb.org
                              wrote on 25 Sept 2024, 11:49 last edited by
                              #21

                              phenomlab you need to be on v4.

                              Alternatively I believe you can update the service worker manually with the one from the ActivityPub branch.

                              P 1 Reply Last reply 25 Sept 2024, 12:02
                              0
                              • J julian@community.nodebb.org
                                25 Sept 2024, 11:49

                                phenomlab you need to be on v4.

                                Alternatively I believe you can update the service worker manually with the one from the ActivityPub branch.

                                P This user is from outside of this forum
                                P This user is from outside of this forum
                                phenomlab@community.nodebb.org
                                wrote on 25 Sept 2024, 12:02 last edited by
                                #22

                                julian thanks. I'll check this later.

                                1 Reply Last reply
                                0
                                • J julian@community.nodebb.org
                                  23 Sept 2024, 16:52

                                  The plugin also successfully removes notifications if they're no longer relevant (e.g. queued posts that have already been handled), and merges notification content just like it does in-app:

                                  22b1cb96-3763-48e9-b890-3f8443ace075-image.png

                                  J This user is from outside of this forum
                                  J This user is from outside of this forum
                                  julian@community.nodebb.org
                                  wrote on 25 Sept 2024, 16:44 last edited by
                                  #23

                                  v0.7.0 of the Push Notification plugin has been released

                                  • Notification related service worker code that was initially included in v4 core is now served by the web-push plugin directly, allowing v3.x compatibility.
                                  • Compatibility updated from v4 to v3.10.x
                                    • Meaning if you want to try this out on your existing NodeBB, you can do so by either waiting for v3.10.0, or by updating to the latest commit on the develop branch
                                  P dave1904@community.nodebb.orgD 2 Replies Last reply 25 Sept 2024, 16:59
                                  0
                                  • J julian@community.nodebb.org
                                    25 Sept 2024, 16:44

                                    v0.7.0 of the Push Notification plugin has been released

                                    • Notification related service worker code that was initially included in v4 core is now served by the web-push plugin directly, allowing v3.x compatibility.
                                    • Compatibility updated from v4 to v3.10.x
                                      • Meaning if you want to try this out on your existing NodeBB, you can do so by either waiting for v3.10.0, or by updating to the latest commit on the develop branch
                                    P This user is from outside of this forum
                                    P This user is from outside of this forum
                                    phenomlab@community.nodebb.org
                                    wrote on 25 Sept 2024, 16:59 last edited by
                                    #24

                                    julian when does 3.10 come out? 😁

                                    J 1 Reply Last reply 25 Sept 2024, 17:46
                                    0
                                    • P phenomlab@community.nodebb.org
                                      25 Sept 2024, 16:59

                                      julian when does 3.10 come out? 😁

                                      J This user is from outside of this forum
                                      J This user is from outside of this forum
                                      julian@community.nodebb.org
                                      wrote on 25 Sept 2024, 17:46 last edited by
                                      #25

                                      phenomlab Right now 😆

                                      P 1 Reply Last reply 26 Sept 2024, 13:34
                                      0
                                      • J julian@community.nodebb.org
                                        25 Sept 2024, 17:46

                                        phenomlab Right now 😆

                                        P This user is from outside of this forum
                                        P This user is from outside of this forum
                                        phenomlab@community.nodebb.org
                                        wrote on 26 Sept 2024, 13:34 last edited by
                                        #26

                                        julian Hmm - still not working for me... 😞

                                        EDIT - works on my Android phone, but not on my PC - guessing it's likely security software.
                                        EDIT 2 - suspicion confirmed. It's caused by NordVPN. If running, the push notification doesn't work - if disabled, it works fine.

                                        J 1 Reply Last reply 28 Sept 2024, 15:13
                                        0
                                        • P phenomlab@community.nodebb.org
                                          26 Sept 2024, 13:34

                                          julian Hmm - still not working for me... 😞

                                          EDIT - works on my Android phone, but not on my PC - guessing it's likely security software.
                                          EDIT 2 - suspicion confirmed. It's caused by NordVPN. If running, the push notification doesn't work - if disabled, it works fine.

                                          J This user is from outside of this forum
                                          J This user is from outside of this forum
                                          julian@community.nodebb.org
                                          wrote on 28 Sept 2024, 15:13 last edited by
                                          #27

                                          phenomlab said in Native Push Notifications Support for NodeBB:
                                          > NordVPN

                                          Thanks for closing the loop! Kind of annoying that NordVPN blocks them...

                                          P 1 Reply Last reply 28 Sept 2024, 18:05
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups