Skip to content

Commit a247170

Browse files
authored
feat: Expose ability to enable browser extensions in WebView2 (#11056)
1 parent fbff638 commit a247170

File tree

10 files changed

+78
-4
lines changed

10 files changed

+78
-4
lines changed

.changes/change-pr-11056.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri": patch:feat
3+
"tauri-runtime-wry": patch:feat
4+
"tauri-runtime": patch:feat
5+
"tauri-utils": patch:feat
6+
---
7+
8+
Expose the ability to enabled browser extensions in WebView2 on Windows.

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri-cli/config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,11 @@
481481
"description": "Whether page zooming by hotkeys is enabled\n\n ## Platform-specific:\n\n - **Windows**: Controls WebView2's [`IsZoomControlEnabled`](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2settings?view=webview2-winrt-1.0.2420.47#iszoomcontrolenabled) setting.\n - **MacOS / Linux**: Injects a polyfill that zooms in and out with `ctrl/command` + `-/=`,\n 20% in each step, ranging from 20% to 1000%. Requires `webview:allow-set-webview-zoom` permission\n\n - **Android / iOS**: Unsupported.",
482482
"default": false,
483483
"type": "boolean"
484+
},
485+
"browserExtensionsEnabled": {
486+
"description": "Whether browser extensions can be installed for the webview process\n\n ## Platform-specific:\n\n - **Windows**: Enables the WebView2 environment's [`AreBrowserExtensionsEnabled`](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2environmentoptions?view=webview2-winrt-1.0.2739.15#arebrowserextensionsenabled)\n - **MacOS / Linux / iOS / Android** - Unsupported.",
487+
"default": false,
488+
"type": "boolean"
484489
}
485490
},
486491
"additionalProperties": false

crates/tauri-runtime-wry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rustc-args = ["--cfg", "docsrs"]
1717
rustdoc-args = ["--cfg", "docsrs"]
1818

1919
[dependencies]
20-
wry = { version = "0.43.1", default-features = false, features = [
20+
wry = { version = "0.44.0", default-features = false, features = [
2121
"drag-drop",
2222
"protocol",
2323
"os-webview",

crates/tauri-runtime-wry/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4072,6 +4072,12 @@ fn create_webview<T: UserEvent>(
40724072
webview_builder = webview_builder.with_https_scheme(false);
40734073
}
40744074

4075+
#[cfg(windows)]
4076+
{
4077+
webview_builder = webview_builder
4078+
.with_browser_extensions_enabled(webview_attributes.browser_extensions_enabled);
4079+
}
4080+
40754081
webview_builder = webview_builder.with_ipc_handler(create_ipc_handler(
40764082
kind,
40774083
window_id.clone(),

crates/tauri-runtime/src/webview.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ pub struct WebviewAttributes {
208208
pub auto_resize: bool,
209209
pub proxy_url: Option<Url>,
210210
pub zoom_hotkeys_enabled: bool,
211+
pub browser_extensions_enabled: bool,
211212
}
212213

213214
impl From<&WindowConfig> for WebviewAttributes {
@@ -235,6 +236,7 @@ impl From<&WindowConfig> for WebviewAttributes {
235236
builder = builder.proxy_url(url.to_owned());
236237
}
237238
builder = builder.zoom_hotkeys_enabled(config.zoom_hotkeys_enabled);
239+
builder = builder.browser_extensions_enabled(config.browser_extensions_enabled);
238240
builder
239241
}
240242
}
@@ -258,6 +260,7 @@ impl WebviewAttributes {
258260
auto_resize: false,
259261
proxy_url: None,
260262
zoom_hotkeys_enabled: false,
263+
browser_extensions_enabled: false,
261264
}
262265
}
263266

@@ -363,6 +366,18 @@ impl WebviewAttributes {
363366
self.zoom_hotkeys_enabled = enabled;
364367
self
365368
}
369+
370+
/// Whether browser extensions can be installed for the webview process
371+
///
372+
/// ## Platform-specific:
373+
///
374+
/// - **Windows**: Enables the WebView2 environment's [`AreBrowserExtensionsEnabled`](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2environmentoptions?view=webview2-winrt-1.0.2739.15#arebrowserextensionsenabled)
375+
/// - **MacOS / Linux / iOS / Android** - Unsupported.
376+
#[must_use]
377+
pub fn browser_extensions_enabled(mut self, enabled: bool) -> Self {
378+
self.browser_extensions_enabled = enabled;
379+
self
380+
}
366381
}
367382

368383
/// IPC handler.

crates/tauri-schema-generator/schemas/config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,11 @@
481481
"description": "Whether page zooming by hotkeys is enabled\n\n ## Platform-specific:\n\n - **Windows**: Controls WebView2's [`IsZoomControlEnabled`](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2settings?view=webview2-winrt-1.0.2420.47#iszoomcontrolenabled) setting.\n - **MacOS / Linux**: Injects a polyfill that zooms in and out with `ctrl/command` + `-/=`,\n 20% in each step, ranging from 20% to 1000%. Requires `webview:allow-set-webview-zoom` permission\n\n - **Android / iOS**: Unsupported.",
482482
"default": false,
483483
"type": "boolean"
484+
},
485+
"browserExtensionsEnabled": {
486+
"description": "Whether browser extensions can be installed for the webview process\n\n ## Platform-specific:\n\n - **Windows**: Enables the WebView2 environment's [`AreBrowserExtensionsEnabled`](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2environmentoptions?view=webview2-winrt-1.0.2739.15#arebrowserextensionsenabled)\n - **MacOS / Linux / iOS / Android** - Unsupported.",
487+
"default": false,
488+
"type": "boolean"
484489
}
485490
},
486491
"additionalProperties": false

crates/tauri-utils/src/config.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,14 @@ pub struct WindowConfig {
14541454
/// - **Android / iOS**: Unsupported.
14551455
#[serde(default)]
14561456
pub zoom_hotkeys_enabled: bool,
1457+
/// Whether browser extensions can be installed for the webview process
1458+
///
1459+
/// ## Platform-specific:
1460+
///
1461+
/// - **Windows**: Enables the WebView2 environment's [`AreBrowserExtensionsEnabled`](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2environmentoptions?view=webview2-winrt-1.0.2739.15#arebrowserextensionsenabled)
1462+
/// - **MacOS / Linux / iOS / Android** - Unsupported.
1463+
#[serde(default)]
1464+
pub browser_extensions_enabled: bool,
14571465
}
14581466

14591467
impl Default for WindowConfig {
@@ -1501,6 +1509,7 @@ impl Default for WindowConfig {
15011509
parent: None,
15021510
proxy_url: None,
15031511
zoom_hotkeys_enabled: false,
1512+
browser_extensions_enabled: false,
15041513
}
15051514
}
15061515
}
@@ -2471,6 +2480,7 @@ mod build {
24712480
let incognito = self.incognito;
24722481
let parent = opt_str_lit(self.parent.as_ref());
24732482
let zoom_hotkeys_enabled = self.zoom_hotkeys_enabled;
2483+
let browser_extensions_enabled = self.browser_extensions_enabled;
24742484

24752485
literal_struct!(
24762486
tokens,
@@ -2516,7 +2526,8 @@ mod build {
25162526
window_effects,
25172527
incognito,
25182528
parent,
2519-
zoom_hotkeys_enabled
2529+
zoom_hotkeys_enabled,
2530+
browser_extensions_enabled
25202531
);
25212532
}
25222533
}

crates/tauri/src/webview/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,18 @@ fn main() {
775775
self.webview_attributes.zoom_hotkeys_enabled = enabled;
776776
self
777777
}
778+
779+
/// Whether browser extensions can be installed for the webview process
780+
///
781+
/// ## Platform-specific:
782+
///
783+
/// - **Windows**: Enables the WebView2 environment's [`AreBrowserExtensionsEnabled`](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2environmentoptions?view=webview2-winrt-1.0.2739.15#arebrowserextensionsenabled)
784+
/// - **MacOS / Linux / iOS / Android** - Unsupported.
785+
#[must_use]
786+
pub fn browser_extensions_enabled(mut self, enabled: bool) -> Self {
787+
self.webview_attributes.browser_extensions_enabled = enabled;
788+
self
789+
}
778790
}
779791

780792
/// Webview.

crates/tauri/src/webview/webview_window.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,18 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
876876
self.webview_builder = self.webview_builder.zoom_hotkeys_enabled(enabled);
877877
self
878878
}
879+
880+
/// Whether browser extensions can be installed for the webview process
881+
///
882+
/// ## Platform-specific:
883+
///
884+
/// - **Windows**: Enables the WebView2 environment's [`AreBrowserExtensionsEnabled`](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2environmentoptions?view=webview2-winrt-1.0.2739.15#arebrowserextensionsenabled)
885+
/// - **MacOS / Linux / iOS / Android** - Unsupported.
886+
#[must_use]
887+
pub fn browser_extensions_enabled(mut self, enabled: bool) -> Self {
888+
self.webview_builder = self.webview_builder.browser_extensions_enabled(enabled);
889+
self
890+
}
879891
}
880892

881893
/// A type that wraps a [`Window`] together with a [`Webview`].

0 commit comments

Comments
 (0)