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..a6f1bd313 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -792,6 +792,24 @@ pub struct WebViewAttributes<'a> { /// Whether JavaScript should be disabled. pub javascript_disabled: bool, + + /// 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 not specified, this is `true` by default. + /// + /// ## 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 `false`, that autofill + /// behavior will be disabled. + /// - **macOS / Linux / Android / iOS**: Unsupported and ignored. + pub general_autofill_enabled: bool, } impl Default for WebViewAttributes<'_> { @@ -834,6 +852,7 @@ impl Default for WebViewAttributes<'_> { }), background_throttling: None, javascript_disabled: false, + general_autofill_enabled: true, } } } @@ -1405,6 +1424,27 @@ impl<'a> WebViewBuilder<'a> { self } + /// 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 not specified, this is `true` by default. + /// + /// ## 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 `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 = 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..014a1b543 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -581,6 +581,10 @@ impl InnerWebView { } } + if let Ok(settings4) = settings.cast::() { + settings4.SetIsGeneralAutofillEnabled(attributes.general_autofill_enabled)?; + } + if let Ok(settings5) = settings.cast::() { settings5.SetIsPinchZoomEnabled(attributes.zoom_hotkeys_enabled)?; }