From 368a3fcaf5a83f01605c024e49830eb04b7fd2ad Mon Sep 17 00:00:00 2001 From: FabianLars Date: Wed, 6 Aug 2025 12:30:17 +0200 Subject: [PATCH 1/4] feat: Add default download handler --- crates/tauri/src/webview/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/tauri/src/webview/mod.rs b/crates/tauri/src/webview/mod.rs index a8e29d7cee0e..6ab8762aaabe 100644 --- a/crates/tauri/src/webview/mod.rs +++ b/crates/tauri/src/webview/mod.rs @@ -572,6 +572,15 @@ tauri::Builder::default() false } })); + } else { + // If no download handler was provided we provide a default that behaves like a browser would by saving the file into the Downloads dir. + pending.download_handler.replace(Arc::new(move |event| { + if let tauri_runtime::webview::DownloadEvent::Requested { url, destination } = event { + dbg!(url); + dbg!(destination); + } + true + })); } let label_ = pending.label.clone(); From c1cf7ce971c53f0e44f864b982027b2c705b18d7 Mon Sep 17 00:00:00 2001 From: FabianLars Date: Thu, 14 Aug 2025 22:57:02 +0200 Subject: [PATCH 2/4] only local --- crates/tauri/src/webview/mod.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/tauri/src/webview/mod.rs b/crates/tauri/src/webview/mod.rs index 8d8ad8740ed5..23f0c09c4228 100644 --- a/crates/tauri/src/webview/mod.rs +++ b/crates/tauri/src/webview/mod.rs @@ -573,13 +573,18 @@ tauri::Builder::default() } })); } else { - // If no download handler was provided we provide a default that behaves like a browser would by saving the file into the Downloads dir. - pending.download_handler.replace(Arc::new(move |event| { - if let tauri_runtime::webview::DownloadEvent::Requested { url, destination } = event { - dbg!(url); - dbg!(destination); + // If no download handler was provided we provide a default handler + // that behaves similar to a browser by saving the file into the Downloads dir if the current url is local. + let label = pending.label.clone(); + let manager = manager.manager_owned(); + pending.download_handler.replace(Arc::new(move |_| { + if let Some(w) = manager.get_webview(&label) { + w.url() + .map(|url| dbg!(w.is_local_url(&url))) + .unwrap_or(false) + } else { + false } - true })); } From 404b0d31eba7011c0a874efd545882cba6fe28f8 Mon Sep 17 00:00:00 2001 From: FabianLars Date: Thu, 14 Aug 2025 23:04:03 +0200 Subject: [PATCH 3/4] rm dbg --- crates/tauri/src/webview/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/tauri/src/webview/mod.rs b/crates/tauri/src/webview/mod.rs index 23f0c09c4228..779b446c0636 100644 --- a/crates/tauri/src/webview/mod.rs +++ b/crates/tauri/src/webview/mod.rs @@ -579,9 +579,7 @@ tauri::Builder::default() let manager = manager.manager_owned(); pending.download_handler.replace(Arc::new(move |_| { if let Some(w) = manager.get_webview(&label) { - w.url() - .map(|url| dbg!(w.is_local_url(&url))) - .unwrap_or(false) + w.url().map(|url| w.is_local_url(&url)).unwrap_or(false) } else { false } From e099430b0a2c9e393410aa169ffd7d5f4987ffa5 Mon Sep 17 00:00:00 2001 From: FabianLars Date: Thu, 14 Aug 2025 23:06:33 +0200 Subject: [PATCH 4/4] changefile --- .changes/default-download.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/default-download.md diff --git a/.changes/default-download.md b/.changes/default-download.md new file mode 100644 index 000000000000..83a5c7135e82 --- /dev/null +++ b/.changes/default-download.md @@ -0,0 +1,5 @@ +--- +tauri: "patch:enhance" +--- + +Tauri will now allow downloads (``) on local URLs (devPath/frontendDist) by default, essentially matching the behavior of browsers. This behavior can be overwritting by providing a custom [download handler](https://docs.rs/tauri/latest/tauri/webview/struct.WebviewWindowBuilder.html#method.on_download) in Rust.