Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .changes/disable-javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
tauri: 'minor:feat'
tauri-runtime-wry: 'minor:feat'
---

Add `WebviewBuilder.disable_javascript` and `WebviewWindowBuilder.disable_javascript` api to disable JavaScript.
3 changes: 1 addition & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/tauri-runtime-wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ wry = { version = "0.49.0", default-features = false, features = [
"protocol",
"os-webview",
"linux-body",
] }
], git = "https://github.com/Simon-Laux/wry", branch = "disable-javascript" }
tao = { version = "0.32.0", default-features = false, features = ["rwh_06"] }
tauri-runtime = { version = "2.3.0", path = "../tauri-runtime" }
tauri-utils = { version = "2.1.1", path = "../tauri-utils" }
Expand Down
4 changes: 4 additions & 0 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4201,6 +4201,10 @@ fn create_webview<T: UserEvent>(
});
}

if webview_attributes.javascript_disabled {
webview_builder = webview_builder.with_javascript_disabled();
}

if let Some(color) = webview_attributes.background_color {
webview_builder = webview_builder.with_background_color(color.into());
}
Expand Down
2 changes: 2 additions & 0 deletions crates/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ pub struct WebviewAttributes {
pub devtools: Option<bool>,
pub background_color: Option<Color>,
pub background_throttling: Option<BackgroundThrottlingPolicy>,
pub javascript_disabled: bool,
}

impl From<&WindowConfig> for WebviewAttributes {
Expand Down Expand Up @@ -285,6 +286,7 @@ impl WebviewAttributes {
devtools: None,
background_color: None,
background_throttling: None,
javascript_disabled: false,
}
}

Expand Down
11 changes: 11 additions & 0 deletions crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,17 @@ fn main() {
self.webview_attributes.background_throttling = Some(policy);
self
}

/// Whether JavaScript should be disabled.
///
/// ## Platform-specific
///
/// - **Android:** Not implemented yet.
#[must_use]
pub fn disable_javascript(mut self) -> Self {
self.webview_attributes.javascript_disabled = true;
self
}
}

/// Webview.
Expand Down
11 changes: 11 additions & 0 deletions crates/tauri/src/webview/webview_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,17 @@ impl<R: Runtime, M: Manager<R>> WebviewWindowBuilder<'_, R, M> {
self.webview_builder = self.webview_builder.background_throttling(policy);
self
}

/// Whether JavaScript should be disabled.
///
/// ## Platform-specific
///
/// - **Android:** Not implemented yet.
#[must_use]
pub fn disable_javascript(mut self) -> Self {
self.webview_builder = self.webview_builder.disable_javascript();
self
}
}

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