ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
508 stars 577 forks source link

@capacitor/network reports "connected" as true when the device is offline. It happens when there is a VPN client running. #1917

Open kpturner opened 9 months ago

kpturner commented 9 months ago

Plugin(s)

@capacitor/network

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 5.5.1
  @capacitor/core: 5.5.1
  @capacitor/android: 5.5.1
  @capacitor/ios: 5.5.1

Installed Dependencies:

  @capacitor/cli: 5.5.0
  @capacitor/core: 5.5.0
  @capacitor/android: 5.5.0
  @capacitor/ios: 5.5.0

Platform(s)

Android IOS

Current Behavior

We have a weird situation where, on Android, the getStatus() method flip-flops between "connected=true" and "connected=false" randomly despite the device being completely offline (airplane mode). When it reports "connected=true" it states that the connection type is "unknown". It turns out that this is being caused by having a VPN client (in this case, NordLayer) installed and active. Although the device is offline, there is something about the VPN client that causes the plugin to think it is online - well it actually continuously toggles between online/offline.

Expected Behavior

Should not think its connected/online when it is not - even with a VPN client.

loremru commented 6 months ago

same

DanGosw commented 5 months ago

Hello, I have the same problem, did you manage to find a solution?

drakedeatonuk commented 2 months ago

Also just noticed this issue. on capacitor 6.

DanGosw commented 2 months ago

@drakedeatonuk did you find any solution?

drakedeatonuk commented 2 months ago

Unfortunately I did not @DanGosw 😞 I would've told you if I had.

DanGosw commented 2 months ago

@drakedeatonuk I found a possible solution, although very ugly, and it is to make requests from time to time to detect a connection, for example using axios, axios.get(https://pokeapi.co/api/v2/pokemon/)

and here I evaluate by the type of response that comes back to me, it may help you depending on your case

karen1au commented 2 months ago

same, using tailscale for vpn :/ (only happening on android)

DanGosw commented 2 months ago

@karen1au Apparently this problem is in many other bookstores that offer the same thing :(

razmans commented 1 month ago

Is it possible to delay any display or alert by x amount of seconds until the VPN kicks in? Then subscribe to the observable.

kpturner commented 1 month ago

Not sure what you mean by "VPN kicks in" in this scenario?