Skip to content

Commit

Permalink
feat(webview2): add method to pass additional args, closes #415 (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Sep 29, 2022
1 parent e8877e2 commit 683f866
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changes/webview2-additional-args.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 0 additions & 5 deletions .changes/webview2-disable-additional-args.md

This file was deleted.

16 changes: 6 additions & 10 deletions src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}
#[cfg(any(
target_os = "linux",
Expand Down Expand Up @@ -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<S: AsRef<str>>(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<S: AsRef<str>>(mut self, additional_args: S) -> Self {
self.platform_specific.additionl_browser_args = Some(additional_args.as_ref().to_string());
self
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/webview/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 683f866

Please sign in to comment.