You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WebView2如何启用密码自动填充?如何设置IsPasswordAutofillEnabled为True

如何设置WebView2的IsPasswordAutofillEnabled属性为True
  • 首先确认项目引用的WebView2 SDK版本不低于1.0.865预览版,低于该版本的SDK不包含该属性,你可以在Visual Studio的NuGet包管理器中直接将WebView2 SDK更新到最新正式版即可。
  • 该属性属于CoreWebView2的配置项,必须等CoreWebView2对象完成初始化后才能修改,直接在控件声明阶段设置会触发空引用报错。

你可以选择以下任意一种方式修改:

方式1:主动等待初始化完成后修改

// WinForms/WPF项目用法一致,以下为WinForm示例代码
private async void Form_Load(object sender, EventArgs e)
{
    // 等待CoreWebView2初始化完成
    await webView21.EnsureCoreWebView2Async();
    // 启用密码自动填充功能
    webView21.CoreWebView2.Settings.IsPasswordAutofillEnabled = true;
}

方式2:在初始化完成事件中修改(更稳妥,适合有自定义初始化逻辑的场景)

public Form1()
{
    InitializeComponent();
    // 注册WebView2初始化完成事件
    webView21.CoreWebView2InitializationCompleted += (s, e) =>
    {
        if (e.IsSuccess)
        {
            webView21.CoreWebView2.Settings.IsPasswordAutofillEnabled = true;
        }
    };
}

修改完成后无需额外配置,WebView2后续加载包含密码输入框的页面时,会自动触发密码保存、自动填充提示。

内容的提问来源于stack exchange,提问作者Sam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 02:54:06