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

"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.

(Lukas Winkler) #14

Hi everyone,

There is a user on our forum ( 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:

(Jeff Atwood) #15

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

(Sam Saffron) #16

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


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

(Lukas Winkler) #18

Answer from the user

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

"Cannot load app" for a meta topic
(Michael Brown) #19

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

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

Make Discourse play nice with the Wayback Machine
(Rafael dos Santos Silva) #20

I recommend the uBlock Origin instead of ABP:

(Michael Brown) #21

That also makes the problem go away :smiley: