Skip to content

Commit

Permalink
feat: Expose ability to enable browser extensions in WebView2 (#11056)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD authored Sep 19, 2024
1 parent fbff638 commit a247170
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .changes/change-pr-11056.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"tauri": patch:feat
"tauri-runtime-wry": patch:feat
"tauri-runtime": patch:feat
"tauri-utils": patch:feat
---

Expose the ability to enabled browser extensions in WebView2 on Windows.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/tauri-cli/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@
"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.",
"default": false,
"type": "boolean"
},
"browserExtensionsEnabled": {
"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.",
"default": false,
"type": "boolean"
}
},
"additionalProperties": false
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-runtime-wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
wry = { version = "0.43.1", default-features = false, features = [
wry = { version = "0.44.0", default-features = false, features = [
"drag-drop",
"protocol",
"os-webview",
Expand Down
6 changes: 6 additions & 0 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4072,6 +4072,12 @@ fn create_webview<T: UserEvent>(
webview_builder = webview_builder.with_https_scheme(false);
}

#[cfg(windows)]
{
webview_builder = webview_builder
.with_browser_extensions_enabled(webview_attributes.browser_extensions_enabled);
}

webview_builder = webview_builder.with_ipc_handler(create_ipc_handler(
kind,
window_id.clone(),
Expand Down
15 changes: 15 additions & 0 deletions crates/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ pub struct WebviewAttributes {
pub auto_resize: bool,
pub proxy_url: Option<Url>,
pub zoom_hotkeys_enabled: bool,
pub browser_extensions_enabled: bool,
}

impl From<&WindowConfig> for WebviewAttributes {
Expand Down Expand Up @@ -235,6 +236,7 @@ impl From<&WindowConfig> for WebviewAttributes {
builder = builder.proxy_url(url.to_owned());
}
builder = builder.zoom_hotkeys_enabled(config.zoom_hotkeys_enabled);
builder = builder.browser_extensions_enabled(config.browser_extensions_enabled);
builder
}
}
Expand All @@ -258,6 +260,7 @@ impl WebviewAttributes {
auto_resize: false,
proxy_url: None,
zoom_hotkeys_enabled: false,
browser_extensions_enabled: false,
}
}

Expand Down Expand Up @@ -363,6 +366,18 @@ impl WebviewAttributes {
self.zoom_hotkeys_enabled = enabled;
self
}

/// Whether browser extensions can be installed for the webview process
///
/// ## Platform-specific:
///
/// - **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)
/// - **MacOS / Linux / iOS / Android** - Unsupported.
#[must_use]
pub fn browser_extensions_enabled(mut self, enabled: bool) -> Self {
self.browser_extensions_enabled = enabled;
self
}
}

/// IPC handler.
Expand Down
5 changes: 5 additions & 0 deletions crates/tauri-schema-generator/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@
"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.",
"default": false,
"type": "boolean"
},
"browserExtensionsEnabled": {
"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.",
"default": false,
"type": "boolean"
}
},
"additionalProperties": false
Expand Down
13 changes: 12 additions & 1 deletion crates/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,14 @@ pub struct WindowConfig {
/// - **Android / iOS**: Unsupported.
#[serde(default)]
pub zoom_hotkeys_enabled: bool,
/// Whether browser extensions can be installed for the webview process
///
/// ## Platform-specific:
///
/// - **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)
/// - **MacOS / Linux / iOS / Android** - Unsupported.
#[serde(default)]
pub browser_extensions_enabled: bool,
}

impl Default for WindowConfig {
Expand Down Expand Up @@ -1501,6 +1509,7 @@ impl Default for WindowConfig {
parent: None,
proxy_url: None,
zoom_hotkeys_enabled: false,
browser_extensions_enabled: false,
}
}
}
Expand Down Expand Up @@ -2471,6 +2480,7 @@ mod build {
let incognito = self.incognito;
let parent = opt_str_lit(self.parent.as_ref());
let zoom_hotkeys_enabled = self.zoom_hotkeys_enabled;
let browser_extensions_enabled = self.browser_extensions_enabled;

literal_struct!(
tokens,
Expand Down Expand Up @@ -2516,7 +2526,8 @@ mod build {
window_effects,
incognito,
parent,
zoom_hotkeys_enabled
zoom_hotkeys_enabled,
browser_extensions_enabled
);
}
}
Expand Down
12 changes: 12 additions & 0 deletions crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,18 @@ fn main() {
self.webview_attributes.zoom_hotkeys_enabled = enabled;
self
}

/// Whether browser extensions can be installed for the webview process
///
/// ## Platform-specific:
///
/// - **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)
/// - **MacOS / Linux / iOS / Android** - Unsupported.
#[must_use]
pub fn browser_extensions_enabled(mut self, enabled: bool) -> Self {
self.webview_attributes.browser_extensions_enabled = enabled;
self
}
}

/// Webview.
Expand Down
12 changes: 12 additions & 0 deletions crates/tauri/src/webview/webview_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,18 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
self.webview_builder = self.webview_builder.zoom_hotkeys_enabled(enabled);
self
}

/// Whether browser extensions can be installed for the webview process
///
/// ## Platform-specific:
///
/// - **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)
/// - **MacOS / Linux / iOS / Android** - Unsupported.
#[must_use]
pub fn browser_extensions_enabled(mut self, enabled: bool) -> Self {
self.webview_builder = self.webview_builder.browser_extensions_enabled(enabled);
self
}
}

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

0 comments on commit a247170

Please sign in to comment.