How Browsers Detect If You Are Offline

Thu, Nov 22, 2012

When I saw the newly released Heyoffline.js library, I was curious to see how it figured out if the user was online or not. This led me to the window.navigator.onLine API and how different browsers implement it. Chrome, Safari and Inernet Explorer 10 make sure that the API detects if the user is connected to a network, while Firefox changes this flag if and only if the user chooses the Work Offline option. A detailed discussion of this difference in implementation is available here.

While this is an interesting example of how despite the efforts put into standardising specifications they get interpreted differently, I was more interested in seeing how different browsers detect if the user is offline or not.

I did some digging around and this is what I found:

  • I expected Internet Explorer to use the Network Connectivity Status Indicator service. It looks like that is not the case. Setting the registry entry HKEY_LOCAL_MACHINESYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet -> EnableActiveProbing to 0 did not seem to have any effect on Explorer’s ability to find if the user is online or not.
  • Google Chrome on Windows uses the Winsock API.aspx”) to detect if a network is available. The relevant source code is here. Look for the method GetCurrentConnectionType()
  • Google Chrome on Linux uses a wrapper around NetworkManager’s D-Bus API. The code is here.
  • Google Chrome on Mac tries to reach 0.0.0.0. This can be seen here. Look for the method SetInitialConnectionType().