Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose ability to enable browser extensions in WebView2 #1356

Merged
merged 3 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading