1

I'm using a custom renderer on a WebView in my project, and I need it to be able to open popups, then I added JavaScriptCanOpenWindowsAutomatically settings to the constructor, but if I set it to true the app crashes at launch, here is my renderer:

[assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(HybridWebViewRenderer))]
namespace ClotureSiadForms.Droid.Renderer
{
    internal class HybridWebViewRenderer : WebViewRenderer
    {
        public HybridWebViewRenderer(Context context) : base(context)
        {
        }
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.Settings.JavaScriptEnabled = true;
                Control.Settings.DomStorageEnabled = true;
                Control.Settings.SavePassword = true;
                //Control.Settings.JavaScriptCanOpenWindowsAutomatically = true;
            }
        }
    }
}

And the error:

10-19 19:05:55.667  HUAWEI RNE-L21  Error   24197   mono-rt [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Types' threw an exception. ---> System.EntryPointNotFoundException: java_interop_jvm_list assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Java.Interop.NativeMethods.java_interop_jvm_list(intptr[],int,int&)
  at Java.Interop.JniRuntime.GetCreatedJavaVMs (System.IntPtr[] handles, System.Int32 bufLen, System.Int32& nVMs) [0x00000] in <d12ba608ed5a4079a11cd8a7188dddcf>:0 
  at Java.Interop.JniRuntime.GetAvailableInvocationPointers () [0x00000] in <d12ba608ed5a4079a11cd8a7188dddcf>:0 
  at Java.Interop.JniRuntime.get_CurrentRuntime () [0x00095] in <d12ba608ed5a4079a11cd8a7188dddcf>:0 
  at Java.Interop.JniEnvironmentInfo..ctor () [0x00006] in <d12ba608ed5a4079a11cd8a7188dddcf>:0 
  at Java.Interop.JniEnvironment+<>c.<.cctor>b__35_0 () [0x00000] in <d12ba608ed5a4079a11cd8a7188dddcf>:0 
  at System.Threading.ThreadLocal`1[T].GetValueSlow () [0x00031] in <a790ddc2dda1484d9a4b87dd85c6ca47>:0 
  at System.Threading.ThreadLocal`1[T].get_Value () [0x0003e] in <a790ddc2dda1484d9a4b87dd85c6ca47>:0 
  at Java.Interop.JniEnvironment+Types.TryFindClass (System.String classname, System.Boolean throwOnError) [0x00014] in <d12ba608ed5a4079a11cd8a7188dddcf>:0 
  at Java.Interop.JniEnvironment+Types.FindClass (System.String classname) [0x00000] in <d12ba608ed5a4079a11cd8a7188dddcf>:0 
  at Java.Interop.JniType..ctor (System.String classname) [0x00006] in <d12ba608ed5a4079a11cd8a7188dddcf>:0 
  at Java.Interop.JniEnvironment+Types..cctor () [0x000d2] in <d12ba608ed5a4079a11cd8a7188dddcf>:0 
   --- End of inner exception stack trace ---
  at Android.Runtime.JNIEnv.IsInstanceOf (System.IntPtr obj, System.IntPtr clazz) [0x0000e] in <ac4226d0aad24df781f4097e7b8b972f>:0 
  at Android.Runtime.JNIEnv.IsGCUserPeer (System.IntPtr value) [0x0000f] in <ac4226d0aad24df781f4097e7b8b972f>:0 

Then, is there another way to make blank links open in the default browser ? Or to prevent this error ?

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
Entretoize
  • 2,124
  • 3
  • 23
  • 44
  • You can try using the [Browser](https://learn.microsoft.com/en-us/xamarin/essentials/open-browser?context=xamarin%2Fandroid&tabs=android) in Xamarin.Essentials to open the connection in your default browser. – Zack Oct 20 '22 at 05:45
  • Ok, but how to open popup from the webview in the browser ? Normal links should stay in the Webview... – Entretoize Oct 20 '22 at 05:49
  • This answer can help you:https://stackoverflow.com/questions/67903119/allow-popups-to-work-in-xamarin-forms-webview#:~:text=1.%20Create%20the%20CustomWebView%20and%20create%20the%20ShowDialog%20method. – Zack Oct 20 '22 at 06:10
  • I don't think so, it shows how to connect javascript to c# and display an alert, I don't see how I could use that, but thank you for trying – Entretoize Oct 20 '22 at 09:37
  • You can try this answer: https://stackoverflow.com/questions/23308601/android-open-pop-up-window-in-my-webview#:~:text=I%20am%20answering,using%20below%20code%3A – Zack Oct 25 '22 at 05:26

0 Answers0