From c5a4c588f273ddaef876f424932b88c28bf2bd28 Mon Sep 17 00:00:00 2001 From: SpikeHD <25207995+SpikeHD@users.noreply.github.com> Date: Fri, 6 Sep 2024 18:59:55 -0700 Subject: [PATCH 1/3] feat: with_browser_extensions_enabled --- src/lib.rs | 15 +++++++++++++++ src/webview2/mod.rs | 1 + 2 files changed, 16 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 114c1f060..e1ded6a8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1091,6 +1091,7 @@ pub(crate) struct PlatformSpecificWebViewAttributes { theme: Option, use_https: bool, scroll_bar_style: ScrollBarStyle, + browser_extensions_enabled: bool, } #[cfg(windows)] @@ -1102,6 +1103,7 @@ impl Default for PlatformSpecificWebViewAttributes { theme: None, use_https: false, // To match macOS & Linux behavior in the context of mixed content. scroll_bar_style: ScrollBarStyle::default(), + browser_extensions_enabled: false, } } } @@ -1153,6 +1155,14 @@ pub trait WebViewBuilderExtWindows { /// Requires WebView2 Runtime version 125.0.2535.41 or higher, does nothing on older versions, /// see https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/?tabs=dotnetcsharp#10253541 fn with_scroll_bar_style(self, style: ScrollBarStyle) -> Self; + + /// Determines whether the ability to install and enable extensions is enabled. + /// + /// By default, extensions are disabled. + /// + /// Requires WebView2 Runtime version 1.0.2210.55 or higher, does nothing on older versions,, + /// see https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/archive?tabs=dotnetcsharp#10221055 + fn with_browser_extensions_enabled(self, enabled: bool) -> Self; } #[cfg(windows)] @@ -1181,6 +1191,11 @@ impl WebViewBuilderExtWindows for WebViewBuilder<'_> { self.platform_specific.scroll_bar_style = style; self } + + fn with_browser_extensions_enabled(mut self, enabled: bool) -> Self { + self.platform_specific.browser_extensions_enabled = enabled; + self + } } #[cfg(target_os = "android")] diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index ff2fdb463..2dfb53474 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -293,6 +293,7 @@ impl InnerWebView { let options = CoreWebView2EnvironmentOptions::default(); options.set_additional_browser_arguments(additional_browser_args); + options.set_are_browser_extensions_enabled(pl_attrs.browser_extensions_enabled); // Get user's system language let lcid = GetUserDefaultUILanguage(); From 979999168604f666accd47f740aead5ee492a11c Mon Sep 17 00:00:00 2001 From: SpikeHD <25207995+SpikeHD@users.noreply.github.com> Date: Fri, 6 Sep 2024 19:09:21 -0700 Subject: [PATCH 2/3] fix: typo --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e1ded6a8e..54e740bb9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1160,7 +1160,7 @@ pub trait WebViewBuilderExtWindows { /// /// By default, extensions are disabled. /// - /// Requires WebView2 Runtime version 1.0.2210.55 or higher, does nothing on older versions,, + /// Requires WebView2 Runtime version 1.0.2210.55 or higher, does nothing on older versions, /// see https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/archive?tabs=dotnetcsharp#10221055 fn with_browser_extensions_enabled(self, enabled: bool) -> Self; } From f07f07c98e6db291c4e700b3611669a67702603e Mon Sep 17 00:00:00 2001 From: SpikeHD <25207995+SpikeHD@users.noreply.github.com> Date: Sat, 7 Sep 2024 18:38:52 -0700 Subject: [PATCH 3/3] fix: add file in .changes --- .changes/change-pr-1356.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/change-pr-1356.md diff --git a/.changes/change-pr-1356.md b/.changes/change-pr-1356.md new file mode 100644 index 000000000..bd4bfa3d5 --- /dev/null +++ b/.changes/change-pr-1356.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +Expose ability to enable browser extensions in WebView2