gree / unity-webview

zlib License
2.3k stars 694 forks source link

window.addEventListener('offline') does not get fired on Android #869

Open brandoncorbin opened 1 year ago

brandoncorbin commented 1 year ago

We are facing an issue with our React / Android application on Unity-Webview. We are trying to implement an offline alert when the user loses internet connection. The alert works as expected when running the app locally, but when we build it for Android, the online/offline events are not being fired. Specifically, the following code is not working:

window.addEventListener("online", handleOnline);
window.addEventListener("offline", handleOffline);

Anyone have any luck getting an offline/online listener working?

KojiNakamaru commented 1 year ago

I adjusted the code in #870 to make navigator.onLine work on Android WebView, and updated binaries. Please note that you need to define UNITYWEBVIEW_ANDROID_ENABLE_NAVIGATOR_ONLINE (cf. https://github.com/gree/unity-webview/tree/9b0686f7f1ee5799c256e89655e7daa75e9ff212#navigatoronline ).