Eilon / MauiHybridWebView

MIT License
202 stars 40 forks source link

Prevent app crash if MAUI View becomes null #49

Open milanio opened 4 months ago

milanio commented 4 months ago

We are experiencing System.InvalidOperationException: VirtualView cannot be null here from time to time on Android. Stacktrace:

Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IWebView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Android.Webkit.WebView, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].get_VirtualView()
HybridWebView.AndroidHybridWebViewClient.ShouldInterceptRequest(WebView view, IWebResourceRequest request)
Android.Webkit.WebViewClient.n_ShouldInterceptRequest_Landroid_webkit_WebView_Landroid_webkit_WebResourceRequest_(IntPtr jnienv, IntPtr native__this, IntPtr native_view, IntPtr native_request)
Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLL_L(_JniMarshal_PPLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1)

This would suggest that Android WebView lives longer that MAUI control and tries to download something. This PR just encapsulates relevant code into a try/catch block and returns '500 - Internal Server Error'