From b863d38ff705e037b297c1651e17775d3dbe473c Mon Sep 17 00:00:00 2001 From: SpikeHD <25207995+SpikeHD@users.noreply.github.com> Date: Sat, 7 Sep 2024 18:55:29 -0700 Subject: [PATCH] feat: Expose ability to enable browser extensions in WebView2 (#1356) * feat: with_browser_extensions_enabled * fix: typo * fix: add file in .changes --- .changes/change-pr-1356.md | 5 +++++ src/lib.rs | 15 +++++++++++++++ src/webview2/mod.rs | 1 + 3 files changed, 21 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 diff --git a/src/lib.rs b/src/lib.rs index 114c1f060..54e740bb9 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();