ServiceWorker thinks I'm offline when I'm not

(Michael Brown) #1

Today I visited a PM, deleted it, silenced the user, then after navigating back (back button) through it I got an offline error. It persisted when I tried to continue going back to meta mainpage.

It looks like you are offline! Please check your network connection and try again.

I can duplicate the problem by visiting the topic normally then hitting Ctrl-R to reload:

The error page that I get is coming from Service Worker:


I’m on Chrome Version 63.0.3239.132 (Official Build) (64-bit)

This kind of smells like it’s related to “Sorry, we couldn’t load that topic, possibly due to a connection problem”.

"Cannot load app" for a meta topic
(Jeff Atwood) #2

Can you repro this @jomaxro?

(EW 👌) #4

I’m not able to access the site at all -with the same error.

" Cannot load app

It looks like you are offline! Please check your network connection and try again. "

I’d tried in Chrome and Firefox last versions. Rebuild is not helping too.

(Kane York) #5

Here’s the worker code being triggered:

if ("navigate" === t.request.mode ||
  "GET" === t.request.method && t.request.headers.get("accept").includes("text/html")) {

t.respondWith(fetch(t.request).catch(function(t) {
        return caches.match(OFFLINE_URL)

So the fetch is failing somehow, which doesn’t include non-200 status codes.

(Jeff Atwood) #6

This is usally due to rogue plugins. Try in Firefox safe mode / Chrome incognito and report back?

(Sam Saffron) #7

One thing I really want is a site setting to disable service workers, firstly this feature means that now everyone has to keep downloading this service worker file (we only have it cached for one day and the name can not change)

Secondly Safari seems to have a slightly more dodgy implementation that may be causing issues, it would be nice to be able to just turn this off on a site to see if it fixes stuff.

(EW 👌) #8

Firefox safe mode / Chrome incognito helped me to see that LetsEncrypt need renewal. Thank you, everything ok now after renewal.

(Joshua Rosenfeld) #9

No - I’ve not been able to repro this over the past 2 weeks of using Discourse. That said, it might be resolved by our recent service worker work…

(Sam Saffron) #10

Not much done, everything I did got reverted.

The underlying issue is what @riking mentioned, there are other exception cases that we are not handling. Probably worth testing DNS failure on local and seeing what comes back from the worker.

Also maybe we should only bother passing through the promise if navigator.onLine is false?
Navigator.onLine - Web APIs | MDN. I wonder how implemented this is these days @awole20?

(Jeff Wong) #11

The complication here is that navigator is not available to service workers, so it might be simpler to detect and handle offline cases from the exception in the catch.

A big issue here is that the service worker catch clause squelches way too much, and perhaps it would be advantageous to pipe a message in the catch clause to the main js app to display or log for debugging.

(Sam Saffron) #12

Possible, or perhaps ship online state to the worker from the app

(Michael Brown) #13

I noticed the other day browsing to sjctoo (which no longer exists) gave the “you are offline” error from ServiceWorker.