ServiceWorker thinks I'm offline when I'm not

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:

image

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


This kind of smells like it’s related to https://meta.discourse.org/t/sorry-we-couldn-t-load-that-topic-possibly-due-to-a-connection-problem/40078/11?u=supermathie.

6 Likes

Can you repro this @jomaxro?

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.

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.

2 Likes

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

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.

4 Likes

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

5 Likes

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…

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?

2 Likes

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.

3 Likes

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

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

3 Likes

Hi everyone,

There is a user on our forum (forum.matomo.org) who is having a really similar issue.

After clicking on an external link and pressing back, he isn’t able to access the forum any more, but only gets an Cannot load app - It looks like you are offline! Please check your network connection and try again error.
Removing the service worker only fixes the issue temporarily.

Does anyone have an idea on how to fix it and avoid getting the error again

You can find more information here:
https://github.com/matomo-org/matomo/issues/12588

Make sure the user making the report is not using a beta browser, that is essential.

Yeah we really need the exact version of the browser, the OS and confirmation this happens with all plugins disabled.

1 Like

I have been experiencing this on lots of Discourse forums lately, running current stable Firefox on Linux and Mac

not using Adblock Plus, but Privacy Badger and Decentraleyes

Answer from the user

(from Matomo forums - Cannot load app · Issue #12588 · matomo-org/matomo · GitHub)

3 Likes

Confirmed! Disabling Adblock Plus also makes my symptoms go away!

There’s definitely an unexpected interaction here with ABP and ServiceWorker.

8 Likes

I recommend the uBlock Origin instead of ABP: https://github.com/gorhill/uBlock#performance

8 Likes

That also makes the problem go away :smiley:

3 Likes