Tryng to set web notifications, but

I am trying to implement web notifications by taking advantage of the tutorial at https://www.sitepoint.com/how-to-use-push-notifications-for-web-applications/, yet, as you may see at my test page https://pizzomarinellafs.inarrivo.net/test/ the initial script stops receiving a 404 error when fetching some script.

There is no 404 error. That test page is requesting notifications… IF your browser allows them to. For Firefox, you will see a little speech bubble appear between the lock and your URL. In Chrome it may block notifications altogether (check in Settings > Privacy and Security > Site Settings > Notifications). I think in Chrome it might be set to auto block and you have a toggle to enable sites to send notifications.

Firefox…
firefox-notification

Chrome Setting…
chrome-notification-setting

Good luck

2 Likes

At any rate I restored the https://pizzomarinellafs.inarrivo.net/test/ page with several error message and Safari reported push manager error:

<script>
console.log("entro");
if ("serviceWorker" in navigator) {

  if ("PushManager" in window) {

    navigator.serviceWorker.register("ServiceWorker.js").then(function(registration) {

      console.log("registration");

    })

    .catch(function() {

      console.log("catched error");

    });

  } else {

    console.log("Push manager error");

  }

} else {

  console.log("serviceWorker error");

}
</script>

while on chrome there is still the 404 error on catch error and no bubble anywhere.
And as you may see at:
https://pizzomarinellafs.inarrivo.net/resources/Images/chromeNotificationsSetting.jpg
my notifications settings seem ok.

On Chrome I still receive:

A bad HTTP response code (404) was received when fetching the script.
As you may check at the given url.

I tried a different implementation and I got:

if ('serviceWorker' in navigator) {
  // then register our service worker
  navigator.serviceWorker.register('/sw.js')
    .then(reg => {
      // display a success message
      console.log(`Service Worker Registration (Scope: ${reg.scope})`);
    })
    .catch(error => {
      // display an error message
      let msg = `Service Worker Error (${error})`;
      console.error(msg);
      // display a warning dialog (using Sweet Alert 2)
    });
} else {
  // happens when the app isn't served over a TLS connection (HTTPS)
  // or if the browser doesn't support service workers
  console.warn('Service Worker not available');
}

Service Worker Error (TypeError: Failed to register a ServiceWorker for scope (‘https://pizzomarinellafs.inarrivo.net/’) with script (‘https://pizzomarinellafs.inarrivo.net/sw.js’): A bad HTTP response code (404) was received when fetching the script.

Ok, the issue boiled to the need to insert an empty file with the referenced name. Now I get to error.