diff --git a/.changes/extension-path.md b/.changes/extension-path.md new file mode 100644 index 000000000..caec2b54d --- /dev/null +++ b/.changes/extension-path.md @@ -0,0 +1,7 @@ +--- +"tauri": "minor:feat" +"tauri-runtime": "minor:feat" +"tauri-runtime-wry": "minor:feat" +--- + +Add `WebviewWindowBuilder/WebviewBuilder::extensions_path` on Linux and Windows. diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index 12629db18..6d256f1c3 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -4283,6 +4283,20 @@ fn create_webview( .with_browser_extensions_enabled(webview_attributes.browser_extensions_enabled); } + #[cfg(any( + windows, + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ))] + { + if let Some(path) = &webview_attributes.extensions_path { + webview_builder = webview_builder.with_extension_path(path); + } + } + webview_builder = webview_builder.with_ipc_handler(create_ipc_handler( kind, window_id.clone(), diff --git a/crates/tauri-runtime/src/webview.rs b/crates/tauri-runtime/src/webview.rs index e17b9e197..e14799bf4 100644 --- a/crates/tauri-runtime/src/webview.rs +++ b/crates/tauri-runtime/src/webview.rs @@ -210,6 +210,7 @@ pub struct WebviewAttributes { pub proxy_url: Option, pub zoom_hotkeys_enabled: bool, pub browser_extensions_enabled: bool, + pub extensions_path: Option, pub use_https_scheme: bool, pub devtools: Option, pub background_color: Option, @@ -272,6 +273,7 @@ impl WebviewAttributes { proxy_url: None, zoom_hotkeys_enabled: false, browser_extensions_enabled: false, + extensions_path: None, use_https_scheme: false, devtools: None, background_color: None, diff --git a/crates/tauri/src/webview/mod.rs b/crates/tauri/src/webview/mod.rs index 987186939..feb818162 100644 --- a/crates/tauri/src/webview/mod.rs +++ b/crates/tauri/src/webview/mod.rs @@ -42,7 +42,7 @@ use crate::{ use std::{ borrow::Cow, hash::{Hash, Hasher}, - path::PathBuf, + path::{Path, PathBuf}, sync::{Arc, Mutex, MutexGuard}, }; @@ -802,6 +802,18 @@ fn main() { self } + /// Set the path from which to load extensions from. Extensions stored in this path should be unpacked Chrome extensions on Windows, and compiled `.so` extensions on Linux. + /// + /// ## Platform-specific: + /// + /// - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled) + /// - **MacOS / iOS / Android** - Unsupported. + #[must_use] + pub fn extensions_path(mut self, path: impl AsRef) -> Self { + self.webview_attributes.extensions_path = Some(path.as_ref().to_path_buf()); + self + } + /// Sets whether the custom protocols should use `https://.localhost` instead of the default `http://.localhost` on Windows and Android. Defaults to `false`. /// /// ## Note diff --git a/crates/tauri/src/webview/webview_window.rs b/crates/tauri/src/webview/webview_window.rs index a81599ed1..b95e6a905 100644 --- a/crates/tauri/src/webview/webview_window.rs +++ b/crates/tauri/src/webview/webview_window.rs @@ -6,7 +6,7 @@ use std::{ borrow::Cow, - path::PathBuf, + path::{Path, PathBuf}, sync::{Arc, MutexGuard}, }; @@ -906,6 +906,18 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { self } + /// Set the path from which to load extensions from. Extensions stored in this path should be unpacked Chrome extensions on Windows, and compiled `.so` extensions on Linux. + /// + /// ## Platform-specific: + /// + /// - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled) + /// - **MacOS / iOS / Android** - Unsupported. + #[must_use] + pub fn extensions_path(mut self, path: impl AsRef) -> Self { + self.webview_builder = self.webview_builder.extensions_path(path); + self + } + /// Sets whether the custom protocols should use `https://.localhost` instead of the default `http://.localhost` on Windows and Android. Defaults to `false`. /// /// ## Note