PWABuilder logs errors even with the example code

127 Views Asked by At

I'm trying to set up a service worker to allow my PWA to work offline. I'm using PWABuilder with the "Offline copy with Backup offline page" strategy. I've followed all the instructions, with the only change to either script being to ensure the URL in the service worker script was pointing at the correct offline fallback page.

When I clear my cache and service workers and then load the home page on the latest stable version of Chrome for Windows, I see several console errors, and the page does not work offline (although it does show the install button in the corner).

The service worker navigation preload request failed with network error: net::ERR_INTERNET_DISCONNECTED.
The FetchEvent for "https://example.com/starturl/" resulted in a network error response: the promise was rejected.
StaleWhileRevalidate.js:136 Uncaught (in promise) no-response: no-response :: [{"url":"https://example.com/starturl/","error":{}}]

I thought that having the start URL be different from the current URL might cause problems so I tried changing it to / but I had the same problem. I tried Googling the errors but didn't find anything relevant.

When I load a subpage (which is also the start URL), I get additional errors.

A bad HTTP response code (404) was received when fetching the script.
Uncaught (in promise) TypeError: Failed to register a ServiceWorker for scope ('https://example.com/starturl/') with script ('https://example.com/starturl/pwabuilder-sw.js'): A bad HTTP response code (404) was received when fetching the script.

I can see from that error that it's trying to load the service worker script from https://example.com/starturl/pwabuilder-sw.js instead of https://example.com/pwabuilder-sw.js. This makes no sense to me, since the instructions state that the file should be on the root, and I'm not even including that URL anywhere in my code.

Running my page through Lighthouse tells me that I don't have any problems with my manifest, and there isn't any JavaScript on either page interfering with the service workers. I'm completely at a loss since I'm using the example code as is (except for changing the URL in the service worker).

If anyone has any idea why this is happening I would love some help.

0

There are 0 best solutions below