react-detect-offline icon indicating copy to clipboard operation
react-detect-offline copied to clipboard

navigator.onLine false positives

Open ash0x0 opened this issue 3 years ago • 3 comments

The component currently fails to detect offline status reliably and produces many false positives. From the navigator.onLine doc: while you can assume that the browser is offline when it returns a false value, you cannot assume that a true value necessarily means that the browser can access the internet.

Relying on navigator.onLine to detect offline status is a good idea. Relying on it to detect online status is not. I suggest changing to reflect this, basically the logic would go like !navigator.online ? definitelyOffline : pollToDetectOnline

If that makes sense, I can PR this. I understand there's a concern with the polling volume and we don't want to be wasteful but as it currently is, there are tons of false positive conditions.

ash0x0 avatar Apr 21 '21 06:04 ash0x0

Hey @ash0x0 We have logic that determines the Browser being used in the user agent. This should prevent any false positives like you are mentioning as they all have different definitions of "online". Can you share a sandbox or example of the false positives ? Particularly , what user agent is causing the false positives?

cwise89 avatar May 27 '21 13:05 cwise89

For me it was electron 12, which is chromium 89. Not sure if electron 13 has the same problem but 11 certainly does.

ash0x0 avatar May 27 '21 13:05 ash0x0

@ash0x0 It may be the issue of the object's state mutation.

BradPrit09 avatar Sep 28 '21 19:09 BradPrit09