Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b863d38

Browse files
authored
feat: Expose ability to enable browser extensions in WebView2 (#1356)
* feat: with_browser_extensions_enabled * fix: typo * fix: add file in .changes
1 parent 9ad972e commit b863d38

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

.changes/change-pr-1356.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wry": patch
3+
---
4+
5+
Expose ability to enable browser extensions in WebView2

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ pub(crate) struct PlatformSpecificWebViewAttributes {
10911091
theme: Option<Theme>,
10921092
use_https: bool,
10931093
scroll_bar_style: ScrollBarStyle,
1094+
browser_extensions_enabled: bool,
10941095
}
10951096

10961097
#[cfg(windows)]
@@ -1102,6 +1103,7 @@ impl Default for PlatformSpecificWebViewAttributes {
11021103
theme: None,
11031104
use_https: false, // To match macOS & Linux behavior in the context of mixed content.
11041105
scroll_bar_style: ScrollBarStyle::default(),
1106+
browser_extensions_enabled: false,
11051107
}
11061108
}
11071109
}
@@ -1153,6 +1155,14 @@ pub trait WebViewBuilderExtWindows {
11531155
/// Requires WebView2 Runtime version 125.0.2535.41 or higher, does nothing on older versions,
11541156
/// see https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/?tabs=dotnetcsharp#10253541
11551157
fn with_scroll_bar_style(self, style: ScrollBarStyle) -> Self;
1158+
1159+
/// Determines whether the ability to install and enable extensions is enabled.
1160+
///
1161+
/// By default, extensions are disabled.
1162+
///
1163+
/// Requires WebView2 Runtime version 1.0.2210.55 or higher, does nothing on older versions,
1164+
/// see https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/archive?tabs=dotnetcsharp#10221055
1165+
fn with_browser_extensions_enabled(self, enabled: bool) -> Self;
11561166
}
11571167

11581168
#[cfg(windows)]
@@ -1181,6 +1191,11 @@ impl WebViewBuilderExtWindows for WebViewBuilder<'_> {
11811191
self.platform_specific.scroll_bar_style = style;
11821192
self
11831193
}
1194+
1195+
fn with_browser_extensions_enabled(mut self, enabled: bool) -> Self {
1196+
self.platform_specific.browser_extensions_enabled = enabled;
1197+
self
1198+
}
11841199
}
11851200

11861201
#[cfg(target_os = "android")]

src/webview2/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ impl InnerWebView {
293293
let options = CoreWebView2EnvironmentOptions::default();
294294

295295
options.set_additional_browser_arguments(additional_browser_args);
296+
options.set_are_browser_extensions_enabled(pl_attrs.browser_extensions_enabled);
296297

297298
// Get user's system language
298299
let lcid = GetUserDefaultUILanguage();

0 commit comments

Comments
 (0)