I want the video to autoplay on the website only if the user is connected to the wifi. I know about the navigator.connection api - but it's not available on safari, and besides it only tells you about the speed of the connection not the type.
Asked
Active
Viewed 1,981 times
5
-
A similar question was asked here: https://stackoverflow.com/questions/25968020/how-to-detect-the-mobile-connection-is-2g-3g-wifi-using-javascript Hope that's helpful! – ShanaSkydancer Feb 24 '18 at 20:49
1 Answers
4
As of December 2020, Safari has made no moves to implement the Network Information API, which as you've noted, provides the navigator.connection
NetworkInformation
object. That's a shame, because other browsers have supplied this for years.
This means there is no equivalent of the iOS-native Reachability APIs on mobile Safari (or desktop Safari, for that matter), so the best you can do is to use a very rough hack like:
- looking up the user's public IP and trying to match it to a database of cell providers, or
- making a test download to roughly gauge connection speed.
For the sake of completeness, according to the MDN, the browsers that do provide navigator.connection
as of December 2020, are:
- Desktop:
- Chrome 61+
- Edge 79+
- Firefox, but only if the user has enabled the
dom.netinfo.enabled
preference - Opera
- Mobile:
- Android WebView 50+
- Chrome Android 38+
- Firefox Android 14+ (same caveat as desktop)
- Opera Android 37+
- Samsung Internet 3+
(Safari and Internet Explorer are the only major browsers conspicuously missing support.)

s3cur3
- 2,749
- 2
- 27
- 42
-
More compatibility info: https://caniuse.com/mdn-api_navigator_connection – V. Rubinetti May 02 '23 at 20:06