Network

Network: Connectivity Status and Events

navigator.onLine in a WebView says little more than "some network interface is up". The Network plugin asks Android's ConnectivityManager instead, through the ACCESS_NETWORK_STATE permission in its manifest, and reports the connection type (wifi, cellular, none or unknown):

Reading and watching the connection in src/js/lab.jsJavaScript
export async function net() {
  return show('network', await Network.getStatus());
}
// in watchPlugins():
  Network.addListener('networkStatusChange', (status) => show('networkStatusChange', status));

Turning the emulator's Wi-Fi off and on from the shell:

Dropping and restoring the connectionShell
adb -s emulator-5558 shell svc wifi disable
adb -s emulator-5558 shell svc wifi enable
Output
LAB network {"connected":true,"connectionType":"wifi"}
LAB networkStatusChange {"connected":false,"connectionType":"none"}
LAB networkStatusChange {"connected":true,"connectionType":"cellular"}
LAB networkStatusChange {"connected":true,"connectionType":"wifi"}
LAB networkStatusChange {"connected":true,"connectionType":"wifi"}
LAB networkStatusChange {"connected":true,"connectionType":"wifi"}

Without Wi-Fi, the app was briefly offline until the emulator's simulated mobile network took over as cellular; Wi-Fi's return then fired three identical events as the link settled. So act on changes of connected, not on every event. The event also fired, unchanged, each time the app returned to the foreground, so make the handler idempotent. Connected still does not mean your server is reachable: a captive portal counts as connected, so a failed request remains the final word.