Skip to content

Commit dc4d794

Browse files
authored
feat(windows, linux): add WebviewWindowBuilder/WebviewBuilder::extensions_path (#11628)
1 parent 4693521 commit dc4d794

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

.changes/extension-path.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": "minor:feat"
3+
"tauri-runtime": "minor:feat"
4+
"tauri-runtime-wry": "minor:feat"
5+
---
6+
7+
Add `WebviewWindowBuilder/WebviewBuilder::extensions_path` on Linux and Windows.

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

+14
Original file line numberDiff line numberDiff line change
@@ -4283,6 +4283,20 @@ fn create_webview<T: UserEvent>(
42834283
.with_browser_extensions_enabled(webview_attributes.browser_extensions_enabled);
42844284
}
42854285

4286+
#[cfg(any(
4287+
windows,
4288+
target_os = "linux",
4289+
target_os = "dragonfly",
4290+
target_os = "freebsd",
4291+
target_os = "netbsd",
4292+
target_os = "openbsd"
4293+
))]
4294+
{
4295+
if let Some(path) = &webview_attributes.extensions_path {
4296+
webview_builder = webview_builder.with_extension_path(path);
4297+
}
4298+
}
4299+
42864300
webview_builder = webview_builder.with_ipc_handler(create_ipc_handler(
42874301
kind,
42884302
window_id.clone(),

crates/tauri-runtime/src/webview.rs

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ pub struct WebviewAttributes {
210210
pub proxy_url: Option<Url>,
211211
pub zoom_hotkeys_enabled: bool,
212212
pub browser_extensions_enabled: bool,
213+
pub extensions_path: Option<PathBuf>,
213214
pub use_https_scheme: bool,
214215
pub devtools: Option<bool>,
215216
pub background_color: Option<Color>,
@@ -272,6 +273,7 @@ impl WebviewAttributes {
272273
proxy_url: None,
273274
zoom_hotkeys_enabled: false,
274275
browser_extensions_enabled: false,
276+
extensions_path: None,
275277
use_https_scheme: false,
276278
devtools: None,
277279
background_color: None,

crates/tauri/src/webview/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use crate::{
4242
use std::{
4343
borrow::Cow,
4444
hash::{Hash, Hasher},
45-
path::PathBuf,
45+
path::{Path, PathBuf},
4646
sync::{Arc, Mutex, MutexGuard},
4747
};
4848

@@ -802,6 +802,18 @@ fn main() {
802802
self
803803
}
804804

805+
/// 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.
806+
///
807+
/// ## Platform-specific:
808+
///
809+
/// - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled)
810+
/// - **MacOS / iOS / Android** - Unsupported.
811+
#[must_use]
812+
pub fn extensions_path(mut self, path: impl AsRef<Path>) -> Self {
813+
self.webview_attributes.extensions_path = Some(path.as_ref().to_path_buf());
814+
self
815+
}
816+
805817
/// Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.
806818
///
807819
/// ## Note

crates/tauri/src/webview/webview_window.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::{
88
borrow::Cow,
9-
path::PathBuf,
9+
path::{Path, PathBuf},
1010
sync::{Arc, MutexGuard},
1111
};
1212

@@ -906,6 +906,18 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
906906
self
907907
}
908908

909+
/// 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.
910+
///
911+
/// ## Platform-specific:
912+
///
913+
/// - **Windows**: Browser extensions must first be enabled. See [`browser_extensions_enabled`](Self::browser_extensions_enabled)
914+
/// - **MacOS / iOS / Android** - Unsupported.
915+
#[must_use]
916+
pub fn extensions_path(mut self, path: impl AsRef<Path>) -> Self {
917+
self.webview_builder = self.webview_builder.extensions_path(path);
918+
self
919+
}
920+
909921
/// Sets whether the custom protocols should use `https://<scheme>.localhost` instead of the default `http://<scheme>.localhost` on Windows and Android. Defaults to `false`.
910922
///
911923
/// ## Note

0 commit comments

Comments
 (0)