itwinjs-core icon indicating copy to clipboard operation
itwinjs-core copied to clipboard

onInternetConnectivityChanged event is called unexpectedly and with a wrong value

Open ShoaibEhsan1 opened this issue 10 months ago • 1 comments

iTwin core provides functionality via overrideInternetConnectivity() so that the apps can control the behavior of internet connectivity. At the same time, it also calls this override function internally based on window.navigator.onLine check (in NativeApp.ts startup function). window.navigator.onLine is not a reliable check and thus it changes the connectivity status from what was set by the app earlier which leads to unwanted results.

Steps to reproduce the behavior:

  1. Listen to onInternetConnectivityChanged event In both frontend and backend in app
  2. disconnect from internet
  3. set the connectivity to Offline via overrideInternetConnectivity
  4. call itwin core startup
  5. if it determines navigator.onLine to true then it raises onInternetConnectivityChanged with Online status which is wrong.

Expected behavior Just like overrideInternetConnectivity, iTwin core also provide a way to override connectivity check in the startup and should not determine connectivity state based on unreliable check.

  • iTwin.js Version [4.10.x]

ShoaibEhsan1 avatar Mar 07 '25 07:03 ShoaibEhsan1

iTwin.js does not provide functionality to override internet connectivity as both NativeHost.overrideInternetConnectivity and NativeApp.overrideInternetConnectivity are internal. Additionally, properties or methods of NativeApp and NativeHost should not be called before startup since we don't guarantee that they will work before startup.

I agree that window.navigator.onLine is not a reliable way to check connectivity status. That being said, to my knowledge, there is no reliable way to check if user machine has access to the internet. Most reliable way might be to make regular pings to some service, but that should not be part of iTwin.js and rather part of the application / framework.

GytisCepk avatar Apr 22 '25 13:04 GytisCepk