Hi there, this looks a great module, but we are seeing the following error in our JS console logs and nothing happening after enabling the configuring the module:

Service Worker error: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.

Digging into this, on line 67 of main.js - it is calling navigator.serviceWorker.register('/sw.js') which doesn't seem to exist unless /sw.js should be registered somehow?

We've tried changing this to the web accessible path (e.g. /modules/contrib/social_pwa/js/sw.j) which now gets rid of that console error and the pop up works - but still no functionality or questions within the browser. Canceling the modal is fine - accepting it will not dismiss the dialog.

Any ideas?

Many thanks,
James

Comments

jamesfk created an issue. See original summary.

heyyo’s picture

I have the exact same issue.

heyyo’s picture

My issue was caused by Nginx. Because the file sw.js is generated by Drupal code, a special NGINX configuration should be added for it, if not NGNIX won't find it.

location = /sw.js {
  try_files $uri @rewrite;
}
bramtenhove’s picture

Thanks heyyo, that is great! I'm curious to know if that also solves your problem jamesfk.

We do define the service worker file in the routing file, but maybe because of the .js extension some webservers don't play nice out of the box.

social_pwa.service-worker:
  path: '/sw.js'
  defaults:
    _controller: '\Drupal\social_pwa\Controller\ServiceWorkerController::serviceWorker'
  requirements:
    _permission: 'access content'
heyyo’s picture

Usually all static files including JS, are processed directly by NGINX and not by Drupal. So NGINX checks if the file exists at the current path.
That's why NGINX was returning 404

bramtenhove’s picture

That makes a lot of sense, thanks!

jamesfk’s picture

Hi Everyone,

We passed this onto our web hosts, omega8cc and they made this change for us, and I'm very pleased to say it has worked, and suddenly the notifications are working on BOA (using nginx).

Thanks for the tip, heyyo.

All the best,
James

fcgreg’s picture

Since it seems like this was a problem specific to NGINX, should we close this issue now?

I'm fairly new around here, so want to defer to @bramtenhove or one of the primary devs. If warranted, we could just include a note about NGINX configuration on the main project page under the "Requirements" section of the "Installation and configuration" section.

fcgreg’s picture

Status: Active » Fixed

Marking as fixed -- problem appears to have been caused by hosting provider configuration.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.