blazormicrosoft-edgemauiwebview2maui-blazor

Maui x Blazor, disable saved info proposition for input


I have a MAUI application that displays a Blazor form through the BlazorWebView. The application is only foreseen to be used on Windows desktops for now. Since the webview is using Microsoft Edge WebView2 under the hood, it naturally leverages some of the edge browser features as well.

In Edge, when you have the focus in a given input field, you may have a popup that displays some previously entered informations from which you can just click an option to fill in the field. example of the popup on the edge browser itself

For the case of my application, it is nowhere near handy to have such a popup, and I believes it hides more things that it is useful.

Now when having this trouble on the edge browser itself, as you can see from the image above, you have a specific button that leads you to the browser settings, and let you disable that option for your browser altogether, which would be a good enough solution for me.

Halas, when running the same code from the webview this time, this is what it looks like.same popup, but running from the MAUI Blazor Webview

As you may see, this time there is no settings since we are not actually running in the brower itself.

I would like to either know if there is a way to either configure that on the machine that runs the client, or block it from some kind of application configuration directly.


Solution

  • There is a setting to do that for windows (so Microsoft Edge WebView2) on the CoreWebView2Settings class: IsGeneralAutofillEnabled which defaults to true indeed.

    Now it's a matter of knowing how to access that configuration setting.

    On the page where you have the webview, make sure that the webview has an x:Name value in order to reference it from the code behind. Then in the code behind of that component/page, you can simply do this (blazorWebView.Handler.PlatformView as Microsoft.UI.Xaml.Controls.WebView2).CoreWebView2.Settings.IsGeneralAutofillEnabled = false; where blazorWebView is the actual x:Name of the webview.

    Also don't forget to protect with#if endif directives since this cast will only work on windows, and that the instance of blazorWebView won't be populated during construction, so you may use the Loaded event to configure it only when the page is actually spinned up.

    Here is how the result looks like from the .cs file of the page that contains the WebView perspective.

    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            Loaded += MainPage_Loaded;
            InitializeComponent();
        }
    
        private void MainPage_Loaded(object sender, EventArgs e)
        {
    #if WINDOWS
            (blazorWebView.Handler.PlatformView as Microsoft.UI.Xaml.Controls.WebView2).CoreWebView2.Settings.IsGeneralAutofillEnabled = false;
    #endif
        }
    }