Best way to check if there is internet?

Peter J. Holzer hjp-python at hjp.at
Sat Feb 26 06:59:50 EST 2022


On 2022-02-22 12:31:42 +0400, Abdur-Rahmaan Janhangeer wrote:
> A front end eng sent me this for how to check for the internet in JS
> 
> https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-online
> 
> But it also says:
> 
> "This attribute is inherently unreliable. A computer can be connected to a
> network without having Internet access."

That actually checks whether the browser is in offline mode. You can set
this mode (in Firefox at least) via File -> Work offline. The browser
will also monitor network interfaces and switch to offline mode if none
(except loopback) are up. But fundamentally it's about the state of the
browser ("... must return false if the user agent will not contact the
network ...") not about whether your computer has "internet access" in
any meaningful sense.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20220226/8e5e206a/attachment.sig>


More information about the Python-list mailing list