A discussion on Discourse’s meta forum addresses a bug where the ServiceWorker incorrectly displays an “offline” error despite an active internet connection. Users report the issue occurs after navigating back via the browser’s back button or refreshing, particularly when using ad-blocking extensions like Adblock Plus, Privacy Badger, or uBlock Origin. The problem stems from the ServiceWorker’s fetch logic, which fails to handle network errors gracefully and may be interfered with by these extensions supermathie, ewanly, lw1, mcnesium, fdellwing, Falco, sam, awlogan, fdellwing, codinghorror, janvlug. The issue is linked to the ServiceWorker’s handling of fetch failures and potential conflicts with browser extensions. Developers discuss potential fixes, including checking navigator.onLine status before showing the offline page sam, sam. Some users suggest reporting the issue to the ad-blocker developers, while others believe Discourse should address the interaction. The discussion also includes a test case showing that certain keywords in topic titles might trigger ad-blockers [featheredtoast](/t/-/77886/32].
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)
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.
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 property - Web APIs | MDN. I wonder how implemented this is these days @awole20?
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.
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