How to use custom WebView and how to use my WebViewClient and WebChomeClient?

Bank 21 Reputation points
2022-06-23T09:35:55.467+00:00

The title has been clearly described

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,867 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,316 Reputation points Microsoft Vendor
    2022-07-01T06:20:12.91+00:00

    Hi @Bank ,
    If you are using WebView, you can customize the Handler and override the CreatePlatformView method to set your WebViewClient and WebChomeClient:

    config handler in MauiProgram

     builder.UseMauiApp<App>().ConfigureMauiHandlers(Handlers =>  
                {  
        #if __ANDROID__  
                   Handlers.AddHandler(typeof(MyCustomWebView), typeof(MyCustomWebViewHandler));  
        #endif  
                });  
    

    Set SetWebViewClient in MyCustomWebViewHandler

     partial class MyCustomWebViewHandler: WebViewHandler  
        {  
            protected override Android.Webkit.WebView CreatePlatformView()  
            {  
                Android.Webkit.WebView customWebView =  new Android.Webkit.WebView(Android.App.Application.Context);  
                customWebView.SetWebViewClient(new MyCustomWebClient());//your WebViewClient   
               customWebView.SetWebChromeClient(new MyCustomWebChomeClient());// your WebChomeClient  
                return customWebView;  
            }  
        }  
    

    For more details , refer to Customize .NET MAUI controls with handlers

    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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,686 Reputation points
    2022-06-23T13:42:01.693+00:00

    not supported by blazor. but an app hosting a WebView should support a blazor server app, but not a blazor WASM

    1 person found this answer helpful.