From 34345aa4f88a16943ea46286571b3104cb1ec3fb Mon Sep 17 00:00:00 2001 From: aoxiangtianyu-go Date: Wed, 31 Dec 2025 23:14:53 +0800 Subject: [PATCH 1/4] feat(windows): add option to control browser autofill behavior --- .changes/general-autofill.md | 5 +++++ src/lib.rs | 36 ++++++++++++++++++++++++++++++++++++ src/webview2/mod.rs | 6 ++++++ 3 files changed, 47 insertions(+) create mode 100644 .changes/general-autofill.md diff --git a/.changes/general-autofill.md b/.changes/general-autofill.md new file mode 100644 index 000000000..ceecf8fd9 --- /dev/null +++ b/.changes/general-autofill.md @@ -0,0 +1,5 @@ +--- +'wry': 'patch:enhance' +--- + +Add an option to control browser-level autofill behavior on Windows. \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 6a9d8dc21..e9bc8a39c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -792,6 +792,22 @@ pub struct WebViewAttributes<'a> { /// Whether JavaScript should be disabled. pub javascript_disabled: bool, + + /// Controls the WebView's browser-level general autofill behavior. + /// + /// When enabled, the WebView may automatically populate form fields using + /// previously stored data such as addresses or contact information. + /// + /// If set to `None`, the default platform behavior is preserved. + /// + /// ## Platform-specific + /// + /// - **Windows**: Supported. On Windows, WebView2's autofill feature (called + /// "Suggestions") may not honor `autocomplete="off"` attributes on input + /// elements in some cases. When this option is `Some(false)`, that autofill + /// behavior will be disabled. + /// - **macOS / Linux / Android / iOS**: Unsupported and ignored. + pub general_autofill_enabled: Option, } impl Default for WebViewAttributes<'_> { @@ -834,6 +850,7 @@ impl Default for WebViewAttributes<'_> { }), background_throttling: None, javascript_disabled: false, + general_autofill_enabled: None, } } } @@ -1405,6 +1422,25 @@ impl<'a> WebViewBuilder<'a> { self } + /// Controls the WebView's browser-level general autofill behavior. + /// + /// When enabled, the WebView may automatically populate form fields using + /// previously stored data such as addresses or contact information. + /// + /// If set to `None`, the default platform behavior is preserved. + /// + /// ## Platform-specific + /// + /// - **Windows**: Supported. On Windows, WebView2's autofill feature (called + /// "Suggestions") may not honor `autocomplete="off"` attributes on input + /// elements in some cases. When this option is `Some(false)`, that autofill + /// behavior will be disabled. + /// - **macOS / Linux / Android / iOS**: Unsupported and ignored. + pub fn with_general_autofill_enabled(mut self, enabled: bool) -> Self { + self.attrs.general_autofill_enabled = Some(enabled); + self + } + /// Consume the builder and create the [`WebView`] from a type that implements [`HasWindowHandle`]. /// /// # Platform-specific: diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index a2f5d5b99..7dde96296 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -581,6 +581,12 @@ impl InnerWebView { } } + if let Some(enabled) = attributes.general_autofill_enabled { + if let Ok(settings4) = settings.cast::() { + settings4.SetIsGeneralAutofillEnabled(enabled)?; + } + } + if let Ok(settings5) = settings.cast::() { settings5.SetIsPinchZoomEnabled(attributes.zoom_hotkeys_enabled)?; } From 2eadced0610311c112921d701d69554d6b946197 Mon Sep 17 00:00:00 2001 From: aoxiangtianyu-go Date: Thu, 1 Jan 2026 01:03:57 +0800 Subject: [PATCH 2/4] refactor(webview): use bool for general autofill setting --- src/lib.rs | 10 +++++----- src/webview2/mod.rs | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e9bc8a39c..ed0b3af14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -804,10 +804,10 @@ pub struct WebViewAttributes<'a> { /// /// - **Windows**: Supported. On Windows, WebView2's autofill feature (called /// "Suggestions") may not honor `autocomplete="off"` attributes on input - /// elements in some cases. When this option is `Some(false)`, that autofill + /// elements in some cases. When this option is `false`, that autofill /// behavior will be disabled. /// - **macOS / Linux / Android / iOS**: Unsupported and ignored. - pub general_autofill_enabled: Option, + pub general_autofill_enabled: bool, } impl Default for WebViewAttributes<'_> { @@ -850,7 +850,7 @@ impl Default for WebViewAttributes<'_> { }), background_throttling: None, javascript_disabled: false, - general_autofill_enabled: None, + general_autofill_enabled: true, } } } @@ -1433,11 +1433,11 @@ impl<'a> WebViewBuilder<'a> { /// /// - **Windows**: Supported. On Windows, WebView2's autofill feature (called /// "Suggestions") may not honor `autocomplete="off"` attributes on input - /// elements in some cases. When this option is `Some(false)`, that autofill + /// elements in some cases. When this option is `false`, that autofill /// behavior will be disabled. /// - **macOS / Linux / Android / iOS**: Unsupported and ignored. pub fn with_general_autofill_enabled(mut self, enabled: bool) -> Self { - self.attrs.general_autofill_enabled = Some(enabled); + self.attrs.general_autofill_enabled = enabled; self } diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index 7dde96296..667016f09 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -581,10 +581,10 @@ impl InnerWebView { } } - if let Some(enabled) = attributes.general_autofill_enabled { - if let Ok(settings4) = settings.cast::() { - settings4.SetIsGeneralAutofillEnabled(enabled)?; - } + if let Ok(settings4) = settings.cast::() { + settings4.SetIsGeneralAutofillEnabled( + attributes.general_autofill_enabled, + )?; } if let Ok(settings5) = settings.cast::() { From b069e6c5c93f52a800d679e32ef8a9452d16f4f6 Mon Sep 17 00:00:00 2001 From: aoxiangtianyu-go Date: Mon, 23 Feb 2026 14:07:33 +0800 Subject: [PATCH 3/4] docs: update with_general_autofill_enabled docs --- src/lib.rs | 10 ++++++++-- src/webview2/mod.rs | 4 +--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ed0b3af14..4746201ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -795,10 +795,13 @@ pub struct WebViewAttributes<'a> { /// Controls the WebView's browser-level general autofill behavior. /// + /// **This option does not disable password or credit card autofill.** + /// /// When enabled, the WebView may automatically populate form fields using /// previously stored data such as addresses or contact information. /// - /// If set to `None`, the default platform behavior is preserved. + /// If not specified, this is `true` by default. + /// Setting this to `false` preserves the default platform behavior. /// /// ## Platform-specific /// @@ -1424,10 +1427,13 @@ impl<'a> WebViewBuilder<'a> { /// Controls the WebView's browser-level general autofill behavior. /// + /// **This option does not disable password or credit card autofill.** + /// /// When enabled, the WebView may automatically populate form fields using /// previously stored data such as addresses or contact information. /// - /// If set to `None`, the default platform behavior is preserved. + /// If not specified, this is `true` by default. + /// Setting this to `false` preserves the default platform behavior. /// /// ## Platform-specific /// diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index 667016f09..014a1b543 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -582,9 +582,7 @@ impl InnerWebView { } if let Ok(settings4) = settings.cast::() { - settings4.SetIsGeneralAutofillEnabled( - attributes.general_autofill_enabled, - )?; + settings4.SetIsGeneralAutofillEnabled(attributes.general_autofill_enabled)?; } if let Ok(settings5) = settings.cast::() { From ebfc81f2416a78d5e2523e8af642a2220340d008 Mon Sep 17 00:00:00 2001 From: aoxiangtianyu-go Date: Mon, 23 Feb 2026 23:12:46 +0800 Subject: [PATCH 4/4] docs: remove uncorrect description --- src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4746201ef..a6f1bd313 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -801,7 +801,6 @@ pub struct WebViewAttributes<'a> { /// previously stored data such as addresses or contact information. /// /// If not specified, this is `true` by default. - /// Setting this to `false` preserves the default platform behavior. /// /// ## Platform-specific /// @@ -1433,7 +1432,6 @@ impl<'a> WebViewBuilder<'a> { /// previously stored data such as addresses or contact information. /// /// If not specified, this is `true` by default. - /// Setting this to `false` preserves the default platform behavior. /// /// ## Platform-specific ///