Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
lib: add navigator.onLine#50224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
lib: add navigator.onLine #50224
Conversation
Uzlopak commented Oct 17, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
8fd4121 to 9969108CompareUh oh!
There was an error while loading. Please reload this page.
96c1f55 to e8e0e9bCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
e8e0e9b to 18a1f74Compare18a1f74 to f08f756CompareUzlopak commented Oct 18, 2023
I investigated getifaddrs used by libuv is just horribly slow. I dont think that fast path makes a difference, when the underlying function call is simply too slow. |
f824b8f to f08f756Compare
tniessen left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained in #39540, I doubt that this is helpful. The existence of non-loopback interfaces does not imply that the device is online.
I understand that for some web applications, being able to detect when the user's (mobile) device has lost connectivity might be important. Also, some browsers allow users to explicitly enable an "offline mode," in which case navigator.onLine also returns false.
However, even in browsers, this is widely unreliable, which is why it is often coupled with actual connectivity checks. The only benefit of navigator.onLine is avoiding additional checks if the property is false. However, if the property is false, then any additional attempt at connecting to a remote resource (e.g., through fetch()) should fail immediately. In other words, even in the unlikely scenario that navigator.onLine is false, the benefit is marginal.
Further, only a fraction of Node.js deployments are on mobile devices that might benefit from this. Enterprise deployments on servers as well as within containers will likely have network setups that will always cause this property to be true.
In command-line tools and such, checking navigator.onLine before fetching some remote resource is not good practice either, similar to how calling fs.exists before reading a file is bad practice.
This implementation is also not spec-compliant unless the relevant events are fired as described in the HTML standard. (We don't have to implement any properties from the HTML standard. The whole navigator object was designed for browsers, not for server-side runtimes. But if we do implement some of those properties, they should at least be spec-compliant.)
On the other hand, always returning true would be spec-compliant and not much less useful than this implementation. It eliminates the need for firing events because the value never changes. (Of course, I'm not actually in favor of adding such a property.)
Uzlopak commented Oct 19, 2023
I am not pushing this. I am just proposing. Maybe it helps to make a final decision regarding navigator being fully implemented or being ripped out. |
GeoffreyBooth commented Oct 26, 2023
Let’s please ping @nodejs/web-standards for all issues and PRs related to |
mcollina left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
jasnell commented Oct 28, 2023
I have to agree with @tniessen's view on this one not being entirely useful and inherently unreliable for most Node.js use cases. |
GeoffreyBooth commented Oct 28, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I don’t think “fully implemented” is something that’s being considered. Bun and Deno each only implement a handful of |
legendecas commented Nov 3, 2023
Filed WinterTC55/proposal-minimum-common-api#61 to discuss the inclusion of Navigator attributes. (Note: Node.js didn't declare itself to be a WinterCG runtime at the moment so this is not a blocker) |
jasnell left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not at all convinced this should be added. While the conversation is pending, I'm going to add an explicit -1 to ensure this doesn't get landed in the meantime.
Motivated by #50200
I did not add the ability to listen on a status change, as I expect that it is problematical as getting the online status is slow.
Using following benchmark I get 2600 ops/s. I could add to
processthe eventsonlineandoffline, if we listen toonlineoroffline. And then i would set a setInterval with lets say 50ms or 250 ms, and check if there was a status change and emit the corresponding event. Maybe if we have listeners, than instead of directly callinggetOnlineStatus, we use the last value derived in thesetInterval.But for now, this is an proposal. Maybe you dont like it and we can stomp this PR into the trashbin :P