Limitations of Browser Offline Detection
You'll learn why navigator.onLine isn't a reliable way to confirm that your app can actually reach the internet, and how local networks can trick it.
The False Promise of navigator.onLine
You might think that checking navigator.onLine tells you whether a user can reach your server, but it only tells you if the browser has some network connection—not whether that connection works.
Think of it like checking if your car has fuel: the gauge might say "full," but that doesn't mean the engine will start or that the roads are open.
Common False Positives
Local Network Connections: If a user is connected to a WiFi router that has no internet access (maybe the ISP is down), navigator.onLine still returns true. The browser sees a network interface and assumes connectivity.
Captive Portals: Hotel or coffee shop WiFi that requires login will show as "online" even though you can't reach any external servers yet.
VPN or Proxy Issues: The device might have a network connection, but intermediate networking layers could be blocking your specific API endpoints.
What It Actually Detects
navigator.onLine essentially checks:
- Is the network adapter enabled?
- Is there an active network interface?
It does not check:
- Can I reach the internet?
- Can I reach my API server?
- Is my connection fast enough to be useful?
The Reality Check
The only way to truly know if your app can communicate with your server is to actually try making a request. Treat navigator.onLine as a helpful hint, not gospel truth. When it's false, you're definitely offline. When it's true, you might still need to verify with a real API call.
Key Takeaway: navigator.onLine detects local network availability, not internet connectivity—use it as an optimization hint, but verify connectivity with actual requests when critical.