navigator.onLine seems to be not reliable

What is the proper way to handle offline mode? I used navigator.onLine but it’s value seems to be not reliable. E.g. I enable airplane mode and/or switch off wifi but the value of onLine is still true. Is there any way to force refresh the value or use any other flags to handle it?

I just tested navigator.onLine and it is working on OSX but document.isConnected always returns true.

Yep, that’s what I’m saying :slight_smile: Sometimes it works, but sometimes it doesn’t.

@kerrishotts

Digging up an old topic here because our XD plugin submission is being denied due to an issue that appears to be an XD bug. I did look through the known issues and didn’t see anything related to this. Photoshop seems to respond immediately or we got lucky with that particular submission.

While in the log directory I ran tail -f -200 AdobeXD.log | grep offline to see the events being logged when turning off my WiFi. At this point I’ve also added a log statement to print PLUGIN is offline when the offline event is fired. Here’s the code:

  useEffect(() => {
    window.addEventListener('online', () => {
      setIsOffline(false)
    })
    window.addEventListener('offline', () => {
      console.log('PLUGIN is offline')
      // Prevents an immediate loss of work in the event of a brief disconnect
      setTimeout(() => {
        if (!window.navigator.onLine) {
          setIsOffline(true)
        }
      }, 5000)
    })

In the logs you’ll notice both almost immediate and delayed responses to the network disconnect:

2021-10-12 14:00:36.893779-0600[59100:1158220(V8 Manager Threa)] debug | cloudDoc | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | Network status offline
2021-10-12 14:00:36.896018-0600[59100:1158220(V8 Manager Threa)] info | liveEdit | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | _handleNetworkStatusChanged(): Network status offline
2021-10-12 14:00:41.908129-0600[59100:1158220(V8 Manager Threa)] info | liveEdit | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | getNetworkStatus(): offline
2021-10-12 14:00:41.999693-0600[59100:1158220(V8 Manager Threa)] always | extensibility | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | PLUGIN is offline

2021-10-12 14:16:29.768805-0600[59100:1158220(V8 Manager Threa)] debug | cloudDoc | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | Network status offline
2021-10-12 14:16:29.770276-0600[59100:1158220(V8 Manager Threa)] info | liveEdit | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | _handleNetworkStatusChanged(): Network status offline
2021-10-12 14:16:29.794716-0600[59100:1158220(V8 Manager Threa)] always | extensibility | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | PLUGIN is offline
2021-10-12 14:16:34.806603-0600[59100:1158220(V8 Manager Threa)] info | liveEdit | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | getNetworkStatus(): offline
2021-10-12 14:16:50.268888-0600[59100:1158220(V8 Manager Threa)] debug | cloudDoc | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | Network status offline
2021-10-12 14:16:50.270915-0600[59100:1158220(V8 Manager Threa)] info | liveEdit | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | _handleNetworkStatusChanged(): Network status offline
2021-10-12 14:16:55.282979-0600[59100:1158220(V8 Manager Threa)] info | liveEdit | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | getNetworkStatus(): offline
2021-10-12 14:16:55.291959-0600[59100:1158220(V8 Manager Threa)] always | extensibility | f7f9171f-7f97-4818-a43c-17b9d6b0b6ad | PLUGIN is offline