Skip to content

Commit

Permalink
feat: Expose ability to enable browser extensions in WebView2 (#1356)
Browse files Browse the repository at this point in the history
* feat: with_browser_extensions_enabled

* fix: typo

* fix: add file in .changes
  • Loading branch information
SpikeHD authored Sep 8, 2024
1 parent 9ad972e commit b863d38
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/change-pr-1356.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Expose ability to enable browser extensions in WebView2
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ pub(crate) struct PlatformSpecificWebViewAttributes {
theme: Option<Theme>,
use_https: bool,
scroll_bar_style: ScrollBarStyle,
browser_extensions_enabled: bool,
}

#[cfg(windows)]
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions src/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b863d38

Please sign in to comment.