MAUI WebView problem with rendering AngularJS

vovanb 1 Reputation point
2022-10-30T10:23:38.19+00:00

My website is not loading properly inside MAUI WebView on Android - templates are not rendering. Fallowing similar problem Issues in loading Angular JS website in Android Webview how I can enable below setting in MAUI project ?

webView.Settings.JavaScriptEnabled = true;  
webView.Settings.AllowFileAccess = true;  
webView.Settings.SetSupportMultipleWindows(true);  
webView.Settings.DatabaseEnabled = true;  
webView.Settings.DatabasePath = "/data/data/" + "/databases/";  

webView.Settings.DomStorageEnabled = true;  
webView.Settings.SetAppCacheEnabled(true);  
webView.Settings.SetAppCacheMaxSize(1024 * 1024 * 8);  
webView.Settings.SetAppCachePath("/data/data/cache/");  
webView.ClearCache(true);   

How I can change above setting to MAUI WebView?

Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2022-10-31T03:14:26.153+00:00

    Hello @vovanb ,

    You could try to find the handle of this MAUI WebView, and get handler.PlatformView, which is a native control of type Android.Webkit.WebView. After that you can set native control properties, invoke native control methods, and subscribe to native control events and so on. For more details, you can refer to .NET MAUI control customization with handlers - .NET MAUI | Microsoft Learn
    (There is an MyEntry derived from Entry in the sample, you can subclass the WebView control)

    Microsoft.Maui.Handlers.WebViewHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>  
            {  
    #if ANDROID  
                if (view is MyCustomWebView)  
                {  
                    Android.Webkit.WebView webView = handler.PlatformView;  
                    webView.Settings.JavaScriptEnabled = true;  
                    webView.Settings....  
                }  
                
    #endif  
     });  
    

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.