MauiHybridWebView icon indicating copy to clipboard operation
MauiHybridWebView copied to clipboard

Prevent app crash if MAUI View becomes null

Open milanio opened this issue 11 months ago • 0 comments

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'

milanio avatar Feb 28 '24 16:02 milanio