Expose SetVirtualHostNameToFolderMapping for offline HTML support (Windows) #14010
CompassionOverload
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
As far as i know use tauri::Manager;
use windows::core::{HSTRING, Interface};
use webview2_com::Microsoft::Web::WebView2::Win32::{
COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND, ICoreWebView2_3,
};
tauri::Builder::deafult()
.setup(|app| {
let window = app.get_webview_window("main").unwrap(); // Change "main" to your window label if needed
window
.with_webview(|wv| unsafe {
wv.controller()
.CoreWebView2()
.unwrap()
.cast::<ICoreWebView2_3>()
.unwrap()
.SetVirtualHostNameToFolderMapping(
&HSTRING::from("hostname"),
&HSTRING::from("A:/fabianlars/testproject/src-tauri/icons"),
COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND(1),
)
.unwrap();
})
.unwrap();
let _ = window.reload();
Ok(())
})
.build(tauri::generate_context!()).unwrap();
Tracked here #5302 - don't expect any progress soon. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Tauri team 👋
I'm not a developer — just a user trying to build a local-first note system using Tauri. I don’t know Rust or C#, but I’m using Svelte and trying to display offline HTML content with local images and videos.
I'm building this system with help from Microsoft Copilot, which guides me through the architecture and tooling. I rely heavily on WebView2 on Windows, and I found that it supports an API called
SetVirtualHostNameToFolderMapping
. This allows mapping a folder to a virtual hostname, so HTML can use relative paths likeimages/foo.png
securely.This would be perfect for my use case, but I couldn’t find a way to use it in Tauri.
Would it be possible to expose this API, or provide a plugin hook to configure folder mapping during WebView initialization?
I’m not sure how hard this is to implement, but I hope it’s something worth considering. Thanks for all your amazing work on Tauri 🙏
While
SetVirtualHostNameToFolderMapping
is specific to Windows, I think the concept behind it — mapping a virtual hostname to a local folder — is broadly useful for offline apps.It would be great if Tauri could offer a cross-platform abstraction for this, so that HTML content can use relative paths like
images/foo.png
consistently across platforms. Even if the implementation differs, having a unified API or plugin interface would make offline resource handling much cleaner and more secure.This would help users like me avoid rewriting HTML paths or relying on unsafe access, and make Tauri even more powerful for local-first applications.
Beta Was this translation helpful? Give feedback.
All reactions