0

I am writing an Electron app and use the Firebase SDK. I am looking for an event or boolean that indicates if the machine is "online".

After I disconnect my development machine from the internet I receive exceptions every few seconds with net::ERR_INTERNET_DISCONNECTED in the console. This means the internals of Firebase are aware that there is no internet connection available. Can I somehow subscribe to this?

For clarification, no user API call of the Firebase SDK raises an exception, they are console output only.

Potential workarounds

The web API defines the window:online and window:offline event but they are both not trustworthy as they might return incorrect values when VPNs or VMs are installed.

There is a second alternative to ping my website every n-seconds, but I don't want to let thousands of machines do that just to see if their clients are online.

HelloWorld
  • 2,392
  • 3
  • 31
  • 68
  • 1
    Ouch, I looked this up for hours and just found a solution a minute after I posted this here: https://stackoverflow.com/questions/11351689/detect-if-firebase-connection-is-lost-regained – HelloWorld Aug 21 '21 at 16:03
  • 1
    Which Firebase product are you working with? Realtime Database or Firestore? Firebase as a platform doesn't do connection tracking. Only Realtime Database has a facility that lets you understand if the SDK is connected to the database or not (and even then, just the database, and not connectivity as a whole for the device). – Doug Stevenson Aug 21 '21 at 16:03
  • 1
    "Firebase raises exceptions that it is not able to connect to its realtime database anymore" Neither of Firebase's databases should treat the lack of a connection as an error condition, unless you perform an operation like a transaction. Can you edit your question to show the [minimal code that reproduces the problem](http://stackoverflow.com/help/mcve)? – Frank van Puffelen Aug 21 '21 at 16:06
  • @FrankvanPuffelen My question was misleading. No user API raises an exception, but the console output indicates that Firebase is aware that it can't connect to the Firebase service. I updated my question in the hope to clarify my situation – HelloWorld Aug 21 '21 at 16:20
  • @DougStevenson I use Firebase Storage + Firebase Realtime Database – HelloWorld Aug 21 '21 at 16:22
  • 1
    Cloud Storage has no such indicator. You already found the relevant question that discusses Realtime Database. Please also see the documentation: https://firebase.google.com/docs/database/web/offline-capabilities#section-connection-state – Doug Stevenson Aug 21 '21 at 16:28
  • That's exactly what I was looking for. Thanks for the confirmation! – HelloWorld Aug 21 '21 at 16:29

0 Answers0