From 683f86665366bb333cb03e05a503a69d0f8eb734 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 29 Sep 2022 20:23:21 +0200 Subject: [PATCH] feat(webview2): add method to pass additional args, closes #415 (#711) --- .changes/webview2-additional-args.md | 5 +++++ .changes/webview2-disable-additional-args.md | 5 ----- src/webview/mod.rs | 16 ++++++---------- src/webview/webview2/mod.rs | 15 ++++++++------- 4 files changed, 19 insertions(+), 22 deletions(-) create mode 100644 .changes/webview2-additional-args.md delete mode 100644 .changes/webview2-disable-additional-args.md diff --git a/.changes/webview2-additional-args.md b/.changes/webview2-additional-args.md new file mode 100644 index 000000000..5396bc7b0 --- /dev/null +++ b/.changes/webview2-additional-args.md @@ -0,0 +1,5 @@ +--- +"wry": "patch" +--- + +Add `WebviewBuilderExtWindows::with_additionl_browser_args` method to pass additional browser args to Webview2 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. \ No newline at end of file diff --git a/.changes/webview2-disable-additional-args.md b/.changes/webview2-disable-additional-args.md deleted file mode 100644 index 5b806b81e..000000000 --- a/.changes/webview2-disable-additional-args.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"wry": "patch" ---- - -Add `WebviewBuilderExtWindows::disable_additionl_browser_args` method to prevent wry from passing additional browser args to Webview2 On Windows. By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection` so if you use this method, you also need to add disable these components by yourself if you want. \ No newline at end of file diff --git a/src/webview/mod.rs b/src/webview/mod.rs index 2f1508400..81c8b325f 100644 --- a/src/webview/mod.rs +++ b/src/webview/mod.rs @@ -214,7 +214,7 @@ impl Default for WebViewAttributes { #[cfg(windows)] #[derive(Default)] pub(crate) struct PlatformSpecificWebViewAttributes { - disable_additionl_browser_args: bool, + additionl_browser_args: Option, } #[cfg(any( target_os = "linux", @@ -484,23 +484,19 @@ impl<'a> WebViewBuilder<'a> { #[cfg(windows)] pub trait WebViewBuilderExtWindows { - /// Disables ther internal use of the additional browser arguments - /// passed to Webview2, so the env var like below isn't overwritten - /// ``` - /// std::env::set_var("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--disable-features=msSmartScreenProtection"); - /// ``` + /// Pass additional args to Webview2 upon creating the webview. /// /// ## Warning /// /// By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection` - /// so if you use this method, you also need to add disable these components by yourself if you want. - fn disable_additionl_browser_args(self) -> Self; + /// so if you use this method, you also need to disable these components by yourself if you want. + fn with_additionl_browser_args>(self, additional_args: S) -> Self; } #[cfg(windows)] impl WebViewBuilderExtWindows for WebViewBuilder<'_> { - fn disable_additionl_browser_args(mut self) -> Self { - self.platform_specific.disable_additionl_browser_args = true; + fn with_additionl_browser_args>(mut self, additional_args: S) -> Self { + self.platform_specific.additionl_browser_args = Some(additional_args.as_ref().to_string()); self } } diff --git a/src/webview/webview2/mod.rs b/src/webview/webview2/mod.rs index 8a5ff0323..aa7daa164 100644 --- a/src/webview/webview2/mod.rs +++ b/src/webview/webview2/mod.rs @@ -118,13 +118,14 @@ impl InnerWebView { options }; - if !pl_attrs.disable_additionl_browser_args { - // remove "mini menu" - See https://github.com/tauri-apps/wry/issues/535 - // and "smart screen" - See https://github.com/tauri-apps/tauri/issues/1345 - let _ = options.SetAdditionalBrowserArguments(PCWSTR::from_raw( - encode_wide("--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection").as_ptr(), - )); - } + let _ = options.SetAdditionalBrowserArguments(PCWSTR::from_raw( + encode_wide(pl_attrs.additionl_browser_args.unwrap_or_else(|| { + // remove "mini menu" - See https://github.com/tauri-apps/wry/issues/535 + // and "smart screen" - See https://github.com/tauri-apps/tauri/issues/1345 + "--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection".to_string() + })) + .as_ptr(), + )); if let Some(data_directory) = data_directory { CreateCoreWebView2EnvironmentWithOptions(