Push Notifications Not functioning

I have read everything I can read in these forums on push notifications, and I cannot figure out why I cannot get them to work. I have not installed the push notifications plugin because the forums say that they are included in Discourse Core. Live notifications are enabled in preferences. Does this feature work without installing the plugin? Also, the user prompt at the top of the page that is supposed to be there is not despite enabling the prompt in settings.

This is the error I see in my logs:

TypeError: Failed to construct 'Notification': Illegal constructor. Use ServiceWorkerRegistration.showNotification() instead.
    at o (https://caseclosed.world/assets/application-5a08d7796085bdd3031b0fbc17dea424f5c6cd21f021924582fcb0200bd8325f.js:12:23300)
    at https://caseclosed.world/assets/application-5a08d7796085bdd3031b0fbc17dea424f5c6cd21f021924582fcb0200bd8325f.js:29:4479

Native browser notifications work without a plugin. If you’re using the single site app then onesignal notifications are used.

Self hosted instances don’t support app notifications, they’re part of the secret sauce used in hosting.

2 Likes

So…I am hosting my own Discourse. Am I to understand that I should expect native browser notifications to work? What am I missing?

1 Like

Live browser notifications should work if you have the site loaded or are using the PWA.

Ok…I think there is a problem, because live browser notifications are not working. Do they only work when one is currently ON that website?

They’ll work if you have a window open on the website, or if you have the mobile PWA installed.

Is your site using https? Is force_https enabled?

@supermathie perhaps that is what I am missing…the mobile PWA. I will give that a try. Do users also need to “watch” categories, or can that field in settings remain blank? I am trying to simplify the process for users to enable notifications. I was hoping that by me setting certain categories to watch by default in settings that they would not have to take that extra step of watching categories. As it is, they have to go to their preferences to enable live notifications, and now it is looking like they need to download the PWA. Still, I am bewildered as to why the user prompt is not appearing at the top of the page.

@Stephen it is funny you mention that, because “force Https” does not appear in my settings. I was running a test Discourse forum on another domain and with another host before launching a new domain with a new host. I no longer see the “force https” in the settings. Https is active, though, or at least that is what the url indicates.

How was this instance installed?

I followed the same steps…I thought the change was due to a Discourse core update, and until now I did not pay much attention to the issue. The only difference was the new domain, and the new host. I am using the Material Design Theme with custome header links and discourse social share components. These are the plugins installed:

The forum is found here https://caseclosed.world

force https is hidden automatically when using Let’s Encrypt.

Your PWA settings look fine - I get prompted to add it on my Android. Have you tried adding it to see if you get mobile notifications?

3 Likes

I downloaded the Discourse app, selected my domain when prompted to choose a forum, and added it to my home screen. I am signed in on the PWA and live notifications are enabled. I am attaching a little video that shows what I did.

TypeError: Failed to construct 'Notification': Illegal constructor. Use ServiceWorkerRegistration.showNotification() instead.
    at https://example.com/assets/application-[spoiler]4f3f9a6090af98121b9336075c31d028a231c99ffbd60bb8ae119baff3133d88.js:12:27295[/spoiler]
    at f (https://example.com/assets/ember_jquery-[spoiler]a40c13c332a81d765d3281335e4a756ef34f0d72a592a96b7e7b37b022328f29.js:17:29538)[/spoiler]
    at T (https://example.com/assets/ember_jquery-[spoiler]a40c13c332a81d765d3281335e4a756ef34f0d72a592a96b7e7b37b022328f29.js:17:30915)[/spoiler]
    at https://example.com/assets/ember_jquery-[spoiler]a40c13c332a81d765d3281335e4a756ef34f0d72a592a96b7e7b37b022328f29.js:17:31429[/spoiler]
    at t.invoke (https://example.com/assets/ember_jquery-[spoiler]a40c13c332a81d765d3281335e4a756ef34f0d72a592a96b7e7b37b022328f29.js:16:6937)[/spoiler]
    at e.t.flush (https://example.com/assets/ember_jquery-[spoiler]a40c13c332a81d765d3281335e4a756ef34f0d72a592a96b7e7b37b022328f29.js:16:5930)[/spoiler]
    at e.t.flush (https://example.com/assets/ember_jquery-[spoiler]a40c13c332a81d765d3281335e4a756ef34f0d72a592a96b7e7b37b022328f29.js:16:7980)[/spoiler]
    at e.r._end (https://example.com/assets/ember_jquery-[spoiler]a40c13c332a81d765d3281335e4a756ef34f0d72a592a96b7e7b37b022328f29.js:16:12654)[/spoiler]
    at MutationObserver._boundAutorunEnd (https://example.com/assets/ember_jquery-[spoiler]a40c13c332a81d765d3281335e4a756ef34f0d72a592a96b7e7b37b022328f29.js:16:8905)[/spoiler]

I can provide you the full links if it helps you, but I blurred them to the public. Let me know if you need the full url’s and I would be happy to provide. Thanks again for your help with this.

Also, I just followed the same steps with the meta.discourse.org forum, and I received the prompt to enable notifications.

I just realized you said that my forum prompts you to “add it” on your Android. Do you mean to say that my forum is prompting you to enable notifications? If so, that is very interesting since it does not prompt me on my android, yet the meta.discourse forum DOES prompt me. I am really scratching my head on this. The meta.discourse is prompting me on my desktop, but my forum is NOT prompting me on my desktop. I have tried Chrome and Edge browsers, and both give me the same result.

Do you have any suspicions as to the cause?

There is a lot of confusion here in this topic. Let’s start over:

  • Discourse Hub App

    • Using discourse.org hosting: You can receive push notification when you add the hosted site to the Discourse Hub app, be it Android or iOS.

    • Not using discourse.org hosting: You won’t get push notification from the Discourse Hub app.

  • Android Google Chrome

    • You can enable push notification from the browser. You will be prompted to do so in a banner after posting your first reply and having TL1. You can also enable it anytime in your profile. You don’t need to add the app to the homescreen to do so (for now).
8 Likes

It looks as though this may be due to a custom plugin on your site - if you run in Safe Mode do you get the same error?

2 Likes

Copy that…regarding the Discourse Hub app, you clarified why I am having difficulty with the app. Regarding Android Google Chrome, I was using a different browser on my Android, which explains that issue. I can confirm now that I get the prompt when using Android Google Chrome.

So, it is all starting to make sense. I am wondering if I can bother you for some direction now. Being that I do not use discourse.org hosting, what do you recommend I do if I want to provide push notifications in other browsers on Android, or to iOS? I am guessing I can install the discourse plugin for desktop notifications to resolve that issue. I was hesitant to do that at first because I understood, from the forums, that discourse core already provided push messaging, and therefore a plugin was unnecessary. Feel free to shoot me straight on this.

I have removed many of the plugins I was using, and I can confirm I no longer get that error. I will add back the plugins, one by one and over the course of a week, to determine which plugin causes that error. Thank you for catching that it is due to a custom plugin. These are the plugins I am currently using:

It does work fine on Firefox on Android, but we don’t support that browser. It works because it adheres to the same web standard every modern browser implements.

iOS Safari browser don’t implement the Web Push Notification web standard, so there is nothing we can do here.

That plugin only “unhides” the web push button for desktop browsers. Support is still the same, Chrome, Firefox & Edge, on the Desktop and Android. We only hide this button on desktop because most people don’t want notifications when the browser is closed on the desktop (and you are playing a game, fullscreen and dies because of the notification lag :wink:).

6 Likes