javascriptandroidgoogle-chromebrowserandroid-browser

JavaScript : window offline event not firing on Android phones (not in Android Browser or Chrome) and navigator.onLine Return always true


JavaScript navigator.onLine command suddenly stop working on Android phones, not in Android Browser, also not in Chrome!

In Android Galaxy, as soon as you put on flight mode (or there is no internet), you get a notification that there is no internet in the following code - but you immediately get a message as if the internet is back.

The following code for example stopped working:

        window.addEventListener('offline', function (e) {
            alert('offline');
        });
        window.addEventListener('online', function (e) {
            alert('online');
        });

And

navigator.onLine

always returns true!

Does anyone have any idea, why is this happening?

Check it yourself on Android: https://codepen.io/Zvi-Redler/pen/JjeMLWR

Or an idea how to get around the problem in the meantime?

(Our QA team found, checked on several devices, we don't know about a special update. I do airplane mode, for sure there is no network and in the past it worked.)


Solution

  • After another check it didn't work because the code was broken - and the code only broke on the Android phone!

    Thanks everyone!

    And if it happens to someone too Keep in mind that it is possible that only on a certain device the code is broken...