Skip to content
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

[wasm] Implement NetworkInterface.GetIsNetworkAvailable and NetworkChange.NetworkAvailabilityChanged #38988

Open
MaximLipnin opened this issue Jul 9, 2020 · 4 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-System.Net
Milestone

Comments

@MaximLipnin
Copy link
Contributor

Since we don't have access to the network cards on browser/WASM, the entire System.Net.NetworkInformation assembly is going to be PNSE excepting tho methods:

  • NetworkInterface.GetIsNetworkAvailable
  • NetworkChange.NetworkAvailabilityChanged

These two methods could probably be implemented on top of https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Net untriaged New issue has not been triaged by the area owner labels Jul 9, 2020
@ghost
Copy link

ghost commented Jul 9, 2020

Tagging subscribers to this area: @dotnet/ncl
Notify danmosemsft if you want to be subscribed.

@akoeplinger akoeplinger added this to the Future milestone Jul 9, 2020
@akoeplinger akoeplinger added arch-wasm WebAssembly architecture and removed untriaged New issue has not been triaged by the area owner labels Jul 9, 2020
@lewing
Copy link
Member

lewing commented May 26, 2022

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 11, 2022
@maraf
Copy link
Member

maraf commented Jul 14, 2022

How should the .NET API behave when the browser API is not available?

We have several situations that can happen

  • The browser API is not available for NodeJS/V8.
  • This browser API is well supported on all new browsers, but if we speak in general, it could happen, that the API we are relying on is missing/disabled/monkey patched etc.

We could deal with it in these ways

  • Silently do nothing (not ideal, but for things like this, it won't fail the application)
    • Pros: app always "works"
    • Cons: developer doesn't know if it works or not
  • Let it fail in javascript (like Cannot read properties of undefined (reading 'onLine') when navigator is not there)
    • Pros: no hardcoded condition in runtime
    • Cons: hard to understand error message for .NET developer
  • On runtime (when running the code) check for the API and when it's missing, throw in .NET (probably NotSupportedException)
    • Pros: works when the API is there on any platform
    • Cons: we don't have a way to tell the developer that is could throw this way
  • Hardcoded condition where we support it and where we don't
    • Cons: the API could still be missing on user's browser; we aren't able show this to the developer (via analyzer)
  • Anything from above + provide a way for the developer to implement a polyfill.

cc @lewing @pavelsavara @kg

@kg
Copy link
Contributor

kg commented Jul 14, 2022

For NetworkInterface.GetIsNetworkAvailable:

  • In any case where we cannot return a valid yes/no answer, we should throw. The developer and user may develop false expectations otherwise. This will be cases where the host doesn't have the API or the API has been disabled/monkeypatched. We should not produce speculative values like "well, this is a blazor app, so they're probably connected to the network, unless it's on 127.x.x.x"
  • It seems like there is no explicit spec for how navigator.onLine works, so we're just hoping that it's close enough to what we want. The MDN pages at least suggest it is, so that's good. But we should be wary of making existing good code do strange things by redefining the meaning of this information.

For the NetworkChange.NetworkAvailabilityChanged event I think as long as it is theoretically possible for the event to ever fire, it should be fine to subscribe to it, but we should throw NSE or PNSE if it's never going to work. We would want to use the online/offline events for this.

Keep in mind that both of these are probably at risk of getting killed by browser anti-fingerprinting measures or something like that.

@ghost ghost added in-pr There is an active PR which will close this issue when it is merged and removed in-pr There is an active PR which will close this issue when it is merged labels Oct 7, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-System.Net
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants