Skip to content

Commit 3dc38b1

Browse files
noamzaksamrbashirlucasfernog
authored
feat(core): expose additional_browser_args to window config (fix: #5757) (#5799)
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com> Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 28133c5 commit 3dc38b1

File tree

11 files changed

+79
-1
lines changed

11 files changed

+79
-1
lines changed

.changes/additional-args-api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": minor
3+
---
4+
5+
Added the `additionalBrowserArgs` option when creating a window.

.changes/additional-args-config.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-utils": minor
3+
---
4+
5+
Added the `additional_browser_args` option to the window configuration.

.changes/additional-args.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": minor
3+
"tauri-runtime-wry": minor
4+
"tauri-runtime": minor
5+
---
6+
7+
Added the `additional_browser_args` option when creating a window.

core/config-schema/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,13 @@
689689
"string",
690690
"null"
691691
]
692+
},
693+
"additionalBrowserArgs": {
694+
"description": "Defines additional browser arguments on Windows. By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection` so if you use this method, you also need to disable these components by yourself if you want.",
695+
"type": [
696+
"string",
697+
"null"
698+
]
692699
}
693700
},
694701
"additionalProperties": false

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ use wry::application::platform::macos::WindowBuilderExtMacOS;
3333
use wry::application::platform::unix::{WindowBuilderExtUnix, WindowExtUnix};
3434
#[cfg(windows)]
3535
use wry::application::platform::windows::{WindowBuilderExtWindows, WindowExtWindows};
36+
#[cfg(windows)]
37+
use wry::webview::WebViewBuilderExtWindows;
3638

3739
#[cfg(target_os = "macos")]
3840
use tauri_utils::TitleBarStyle;
@@ -3051,6 +3053,12 @@ fn create_webview<T: UserEvent>(
30513053
if let Some(user_agent) = webview_attributes.user_agent {
30523054
webview_builder = webview_builder.with_user_agent(&user_agent);
30533055
}
3056+
3057+
#[cfg(windows)]
3058+
if let Some(additional_browser_args) = webview_attributes.additional_browser_args {
3059+
webview_builder = webview_builder.with_additional_browser_args(&additional_browser_args);
3060+
}
3061+
30543062
if let Some(handler) = ipc_handler {
30553063
webview_builder = webview_builder.with_ipc_handler(create_ipc_handler(
30563064
context,

core/tauri-runtime/src/webview.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct WebviewAttributes {
2828
pub file_drop_handler_enabled: bool,
2929
pub clipboard: bool,
3030
pub accept_first_mouse: bool,
31+
pub additional_browser_args: Option<String>,
3132
}
3233

3334
impl WebviewAttributes {
@@ -41,6 +42,7 @@ impl WebviewAttributes {
4142
file_drop_handler_enabled: true,
4243
clipboard: false,
4344
accept_first_mouse: false,
45+
additional_browser_args: None,
4446
}
4547
}
4648

@@ -88,6 +90,13 @@ impl WebviewAttributes {
8890
self.accept_first_mouse = accept;
8991
self
9092
}
93+
94+
/// Sets additional browser arguments. **Windows Only**
95+
#[must_use]
96+
pub fn additional_browser_args(mut self, additional_args: &str) -> Self {
97+
self.additional_browser_args = Some(additional_args.to_string());
98+
self
99+
}
91100
}
92101

93102
/// Do **NOT** implement this trait except for use in a custom [`Runtime`](crate::Runtime).

core/tauri-utils/src/config.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ pub struct WindowConfig {
884884
/// [tabbing identifier]: <https://developer.apple.com/documentation/appkit/nswindow/1644704-tabbingidentifier>
885885
#[serde(default, alias = "tabbing-identifier")]
886886
pub tabbing_identifier: Option<String>,
887+
/// Defines additional browser arguments on Windows. By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection`
888+
/// so if you use this method, you also need to disable these components by yourself if you want.
889+
#[serde(default, alias = "additional-browser-args")]
890+
pub additional_browser_args: Option<String>,
887891
}
888892

889893
impl Default for WindowConfig {
@@ -918,6 +922,7 @@ impl Default for WindowConfig {
918922
hidden_title: false,
919923
accept_first_mouse: false,
920924
tabbing_identifier: None,
925+
additional_browser_args: None,
921926
}
922927
}
923928
}
@@ -3061,6 +3066,7 @@ mod build {
30613066
let hidden_title = self.hidden_title;
30623067
let accept_first_mouse = self.accept_first_mouse;
30633068
let tabbing_identifier = opt_str_lit(self.tabbing_identifier.as_ref());
3069+
let additional_browser_args = opt_str_lit(self.additional_browser_args.as_ref());
30643070

30653071
literal_struct!(
30663072
tokens,
@@ -3093,7 +3099,8 @@ mod build {
30933099
title_bar_style,
30943100
hidden_title,
30953101
accept_first_mouse,
3096-
tabbing_identifier
3102+
tabbing_identifier,
3103+
additional_browser_args
30973104
);
30983105
}
30993106
}

core/tauri/src/app.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,9 @@ impl<R: Runtime> Builder<R> {
15741574
if let Some(ua) = &config.user_agent {
15751575
webview_attributes = webview_attributes.user_agent(&ua.to_string());
15761576
}
1577+
if let Some(args) = &config.additional_browser_args {
1578+
webview_attributes = webview_attributes.additional_browser_args(&args.to_string());
1579+
}
15771580
if !config.file_drop_enabled {
15781581
webview_attributes = webview_attributes.disable_file_drop_handler();
15791582
}

core/tauri/src/window.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,22 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
533533
self
534534
}
535535

536+
/// Set additional arguments for the webview.
537+
///
538+
/// ## Platform-specific
539+
///
540+
/// - **macOS / Linux / Android / iOS**: Unsupported.
541+
///
542+
/// ## Warning
543+
///
544+
/// By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection`
545+
/// so if you use this method, you also need to disable these components by yourself if you want.
546+
#[must_use]
547+
pub fn additional_browser_args(mut self, additional_args: &str) -> Self {
548+
self.webview_attributes.additional_browser_args = Some(additional_args.to_string());
549+
self
550+
}
551+
536552
/// Data directory for the webview.
537553
#[must_use]
538554
pub fn data_directory(mut self, data_directory: PathBuf) -> Self {

tooling/api/src/window.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,10 @@ interface WindowOptions {
21412141
* The user agent for the webview.
21422142
*/
21432143
userAgent?: string
2144+
/**
2145+
* Additional arguments for the webview. **Windows Only**
2146+
*/
2147+
additionalBrowserArguments?: string
21442148
}
21452149

21462150
function mapMonitor(m: Monitor | null): Monitor | null {

0 commit comments

Comments
 (0)