On-line detection - detect working internet access

Hello,

I’m looking for a way to detect working internet access for my add-on background script. I need this to prevent execution of some scheduled tasks that creates thumbnails of user defined pages.

Being off-line is actually happening quite often, mostly when PC is waking up from sleep and the network is not fully initialized. I could solve this use case with a wake-up detector code but that would solve only this one use-case and would like to have a proper solution.

I’ve found window.navigator.onLine


but it doesn’t work at all even if I disable my whole network adapter.

Is there a better way? Maybe some simple “ping” AJAX to google.com? (something that would be allowed by add-on Policies).

Have you had a look at the compat table? It does not work on Linux at all in Firefox. I just use that either way and - if absolutely necessary handle 0 responses as offline and just adjust my scripts to handle not being online more gracefully.

In your case that likely means that you’ll want to ping something first, yes.