Skip to content

Commit 001c8fe

Browse files
feat(webview2): add option to disable browser-level autofill on Windows (#14722)
* feat(webview2): add option to disable browser-level autofill on Windows * docs(api): set disableAutofill api since to 2.11.0 * docs(disable_autofill ): unify documentation * Update .changes/.disable-autofill.md Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> * refactor(runtime): rename disable_autofill to general_autofill_enabled * refactor(api): delete general autofill option in WindowOptions Co-authored-by: Copilot <copilot@github.com> * Update crates/tauri-runtime-wry/src/lib.rs Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> * fix: fix default value for general_autofill_enabled * fix(schema): fix default value for general_autofill_enabled * Clean up * Revert new line --------- Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> Co-authored-by: Tony <legendmastertony@gmail.com>
1 parent 6da2bad commit 001c8fe

9 files changed

Lines changed: 153 additions & 3 deletions

File tree

.changes/disable-autofill.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'tauri-runtime': 'minor:feat'
3+
'tauri-runtime-wry': 'minor:feat'
4+
'tauri-utils': 'minor:feat'
5+
'tauri': 'minor:feat'
6+
'@tauri-apps/api': 'minor:feat'
7+
---
8+
9+
Add a WebView option to control browser-level general autofill behavior. This option does not disable password or credit card autofill. On Windows (WebView2), setting it to true disables the general autofill "Suggestions" UI, which may appear even when `autocomplete="off"` is specified on input elements. On Linux, macOS, iOS, and Android, this option is currently unsupported and performs no operation.

crates/tauri-cli/config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,11 @@
625625
"string",
626626
"null"
627627
]
628+
},
629+
"generalAutofillEnabled": {
630+
"description": "Controls the WebView's browser-level general autofill behavior.\n\n **This option does not disable password or credit card autofill.**\n\n When set to `false`, the WebView will not automatically populate\n general form fields using previously stored data such as addresses\n or contact information.\n\n If not specified, this is `true` by default.\n\n ## Platform-specific\n\n - **Windows**: Supported. WebView2's autofill feature (called\n \"Suggestions\") may not honor `autocomplete=\"off\"` on input\n elements in some cases.\n - **Linux / Android / iOS / macOS**: Unsupported and performs no\n operation.",
631+
"default": true,
632+
"type": "boolean"
628633
}
629634
},
630635
"additionalProperties": false

crates/tauri-runtime-wry/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4760,7 +4760,8 @@ You may have it installed on another user account, but it is not available for t
47604760
.with_accept_first_mouse(webview_attributes.accept_first_mouse)
47614761
.with_incognito(webview_attributes.incognito)
47624762
.with_clipboard(webview_attributes.clipboard)
4763-
.with_hotkeys_zoom(webview_attributes.zoom_hotkeys_enabled);
4763+
.with_hotkeys_zoom(webview_attributes.zoom_hotkeys_enabled)
4764+
.with_general_autofill_enabled(webview_attributes.general_autofill_enabled);
47644765

47654766
if url != "about:blank" {
47664767
webview_builder = webview_builder.with_url(&url);

crates/tauri-runtime/src/webview.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,24 @@ pub struct WebviewAttributes {
371371
/// see https://docs.rs/objc2-web-kit/latest/objc2_web_kit/struct.WKWebView.html#method.allowsLinkPreview
372372
pub allow_link_preview: bool,
373373
pub scroll_bar_style: ScrollBarStyle,
374+
/// Controls the WebView's browser-level general autofill behavior.
375+
///
376+
/// **This option does not disable password or credit card autofill.**
377+
///
378+
/// When set to `false`, the WebView will not automatically populate
379+
/// general form fields using previously stored data such as addresses
380+
/// or contact information.
381+
///
382+
/// If not specified, this is `true` by default.
383+
///
384+
/// ## Platform-specific
385+
///
386+
/// - **Windows**: Supported. WebView2's autofill feature (called
387+
/// "Suggestions") may not honor `autocomplete="off"` on input
388+
/// elements in some cases.
389+
/// - **Linux / Android / iOS / macOS**: Unsupported and performs no
390+
/// operation.
391+
pub general_autofill_enabled: bool,
374392
/// Allows overriding the keyboard accessory view on iOS.
375393
/// Returning `None` effectively removes the view.
376394
///
@@ -441,7 +459,8 @@ impl From<&WindowConfig> for WebviewAttributes {
441459
#[cfg(windows)]
442460
ConfigScrollBarStyle::FluentOverlay => ScrollBarStyle::FluentOverlay,
443461
_ => ScrollBarStyle::Default,
444-
});
462+
})
463+
.general_autofill_enabled(config.general_autofill_enabled);
445464

446465
#[cfg(any(not(target_os = "macos"), feature = "macos-private-api"))]
447466
{
@@ -516,6 +535,7 @@ impl WebviewAttributes {
516535
javascript_disabled: false,
517536
allow_link_preview: true,
518537
scroll_bar_style: ScrollBarStyle::Default,
538+
general_autofill_enabled: true,
519539
#[cfg(target_os = "ios")]
520540
input_accessory_view_builder: None,
521541
#[cfg(windows)]
@@ -807,6 +827,29 @@ impl WebviewAttributes {
807827
self.scroll_bar_style = style;
808828
self
809829
}
830+
831+
/// Controls the WebView's browser-level general autofill behavior.
832+
///
833+
/// **This option does not disable password or credit card autofill.**
834+
///
835+
/// When set to `false`, the WebView will not automatically populate
836+
/// general form fields using previously stored data such as addresses
837+
/// or contact information.
838+
///
839+
/// By default, this is `true`.
840+
///
841+
/// ## Platform-specific
842+
///
843+
/// - **Windows**: Supported. WebView2's autofill feature (called
844+
/// "Suggestions") may not honor `autocomplete="off"` on input
845+
/// elements in some cases.
846+
/// - **Linux / Android / iOS / macOS**: Unsupported and performs no
847+
/// operation.
848+
#[must_use]
849+
pub fn general_autofill_enabled(mut self, enabled: bool) -> Self {
850+
self.general_autofill_enabled = enabled;
851+
self
852+
}
810853
}
811854

812855
/// IPC handler.

crates/tauri-schema-generator/schemas/config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,11 @@
625625
"string",
626626
"null"
627627
]
628+
},
629+
"generalAutofillEnabled": {
630+
"description": "Controls the WebView's browser-level general autofill behavior.\n\n **This option does not disable password or credit card autofill.**\n\n When set to `false`, the WebView will not automatically populate\n general form fields using previously stored data such as addresses\n or contact information.\n\n If not specified, this is `true` by default.\n\n ## Platform-specific\n\n - **Windows**: Supported. WebView2's autofill feature (called\n \"Suggestions\") may not honor `autocomplete=\"off\"` on input\n elements in some cases.\n - **Linux / Android / iOS / macOS**: Unsupported and performs no\n operation.",
631+
"default": true,
632+
"type": "boolean"
628633
}
629634
},
630635
"additionalProperties": false

crates/tauri-utils/src/config.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,25 @@ pub struct WindowConfig {
22702270
/// By default the system uses the foreground scene.
22712271
#[serde(default, alias = "requested-by-scene-identifier")]
22722272
pub requested_by_scene_identifier: Option<String>,
2273+
/// Controls the WebView's browser-level general autofill behavior.
2274+
///
2275+
/// **This option does not disable password or credit card autofill.**
2276+
///
2277+
/// When set to `false`, the WebView will not automatically populate
2278+
/// general form fields using previously stored data such as addresses
2279+
/// or contact information.
2280+
///
2281+
/// If not specified, this is `true` by default.
2282+
///
2283+
/// ## Platform-specific
2284+
///
2285+
/// - **Windows**: Supported. WebView2's autofill feature (called
2286+
/// "Suggestions") may not honor `autocomplete="off"` on input
2287+
/// elements in some cases.
2288+
/// - **Linux / Android / iOS / macOS**: Unsupported and performs no
2289+
/// operation.
2290+
#[serde(default = "default_true", alias = "general-autofill-enabled")]
2291+
pub general_autofill_enabled: bool,
22732292
}
22742293

22752294
impl Default for WindowConfig {
@@ -2335,6 +2354,7 @@ impl Default for WindowConfig {
23352354
activity_name: None,
23362355
created_by_activity_name: None,
23372356
requested_by_scene_identifier: None,
2357+
general_autofill_enabled: true,
23382358
}
23392359
}
23402360
}
@@ -3872,6 +3892,7 @@ mod build {
38723892
let activity_name = opt_lit(self.activity_name.as_ref());
38733893
let created_by_activity_name = opt_lit(self.created_by_activity_name.as_ref());
38743894
let requested_by_scene_identifier = opt_lit(self.requested_by_scene_identifier.as_ref());
3895+
let general_autofill_enabled = self.general_autofill_enabled;
38753896

38763897
literal_struct!(
38773898
tokens,
@@ -3935,7 +3956,8 @@ mod build {
39353956
scroll_bar_style,
39363957
activity_name,
39373958
created_by_activity_name,
3938-
requested_by_scene_identifier
3959+
requested_by_scene_identifier,
3960+
general_autofill_enabled
39393961
);
39403962
}
39413963
}

crates/tauri/src/webview/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,29 @@ fn main() {
11791179
self
11801180
}
11811181

1182+
/// Controls the WebView's browser-level general autofill behavior.
1183+
///
1184+
/// **This option does not disable password or credit card autofill.**
1185+
///
1186+
/// When set to `false`, the WebView will not automatically populate
1187+
/// general form fields using previously stored data such as addresses
1188+
/// or contact information.
1189+
///
1190+
/// By default, this is `true`.
1191+
///
1192+
/// ## Platform-specific
1193+
///
1194+
/// - **Windows**: Supported. WebView2's autofill feature (called
1195+
/// "Suggestions") may not honor `autocomplete="off"` on input
1196+
/// elements in some cases.
1197+
/// - **Linux / Android / iOS / macOS**: Unsupported and performs no
1198+
/// operation.
1199+
#[must_use]
1200+
pub fn general_autofill_enabled(mut self, enabled: bool) -> Self {
1201+
self.webview_attributes = self.webview_attributes.general_autofill_enabled(enabled);
1202+
self
1203+
}
1204+
11821205
/// Whether to show a link preview when long pressing on links. Available on macOS and iOS only.
11831206
///
11841207
/// Default is true.

crates/tauri/src/webview/webview_window.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,29 @@ impl<R: Runtime, M: Manager<R>> WebviewWindowBuilder<'_, R, M> {
12261226
self
12271227
}
12281228

1229+
/// Controls the WebView's browser-level general autofill behavior.
1230+
///
1231+
/// **This option does not disable password or credit card autofill.**
1232+
///
1233+
/// When set to `false`, the WebView will not automatically populate
1234+
/// general form fields using previously stored data such as addresses
1235+
/// or contact information.
1236+
///
1237+
/// By default, this is `true`.
1238+
///
1239+
/// ## Platform-specific
1240+
///
1241+
/// - **Windows**: Supported. WebView2's autofill feature (called
1242+
/// "Suggestions") may not honor `autocomplete="off"` on input
1243+
/// elements in some cases.
1244+
/// - **Linux / Android / iOS / macOS**: Unsupported and performs no
1245+
/// operation.
1246+
#[must_use]
1247+
pub fn general_autofill_enabled(mut self, enabled: bool) -> Self {
1248+
self.webview_builder = self.webview_builder.general_autofill_enabled(enabled);
1249+
self
1250+
}
1251+
12291252
/// Allows overriding the keyboard accessory view on iOS.
12301253
/// Returning `None` effectively removes the view.
12311254
///

packages/api/src/webview.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,25 @@ interface WebviewOptions {
897897
* - **Linux / Android / iOS / macOS**: Unsupported. Only supports `Default` and performs no operation.
898898
*/
899899
scrollBarStyle?: ScrollBarStyle
900+
/**
901+
* Controls the WebView's browser-level general autofill behavior.
902+
*
903+
* **This option does not disable password or credit card autofill.**
904+
*
905+
* When set to `false`, the WebView will not automatically populate general form
906+
* fields using previously stored data such as addresses or contact information.
907+
*
908+
* If not specified, this is `true` by default.
909+
*
910+
* ## Platform-specific
911+
*
912+
* - **Windows**: Supported. WebView2's autofill feature (called "Suggestions")
913+
* may not honor `autocomplete="off"` on input elements in some cases.
914+
* - **Linux / Android / iOS / macOS**: Unsupported and performs no operation.
915+
*
916+
* @since 2.11.0
917+
*/
918+
generalAutofillEnabled?: boolean
900919
}
901920

902921
export { Webview, getCurrentWebview, getAllWebviews }

0 commit comments

Comments
 (0)