diff --git a/packages/desktop/src-tauri/src/lib.rs b/packages/desktop/src-tauri/src/lib.rs index e086acd9364..c19fa63c6c6 100644 --- a/packages/desktop/src-tauri/src/lib.rs +++ b/packages/desktop/src-tauri/src/lib.rs @@ -328,7 +328,39 @@ pub fn run() { .hidden_title(true); #[cfg(windows)] - let window_builder = window_builder.decorations(false); + let window_builder = { + let app_handle = app.clone(); + window_builder + .decorations(false) + .on_navigation(move |url| { + let scheme = url.scheme(); + + // Allow internal Tauri protocols + if scheme == "tauri" || scheme == "app" || scheme == "file" { + return true; + } + + // Allow localhost (dev server & local sidecar) + if scheme == "http" || scheme == "https" { + if let Some(host) = url.host_str() { + if host == "localhost" || host == "127.0.0.1" || host == "::1" { + return true; + } + } + // External URL - open in system browser + let _ = app_handle.opener().open_url(url.as_str(), None::<&str>); + return false; + } + + // Handle special protocols (mailto, tel, etc.) + if scheme == "mailto" || scheme == "tel" { + let _ = app_handle.opener().open_url(url.as_str(), None::<&str>); + return false; + } + + true + }) + }; let window = window_builder.build().expect("Failed to create window"); diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsx index fe9e3f92e24..ad4c55ef5f0 100644 --- a/packages/desktop/src/index.tsx +++ b/packages/desktop/src/index.tsx @@ -338,8 +338,18 @@ render(() => { onMount(() => { document.addEventListener("click", handleClick) + + // Disable WebView2 browser context menu on Windows (Back/Forward buttons) + const handleContextMenu = platform.os === "windows" ? (e: MouseEvent) => e.preventDefault() : null + if (handleContextMenu) { + document.addEventListener("contextmenu", handleContextMenu, true) + } + onCleanup(() => { document.removeEventListener("click", handleClick) + if (handleContextMenu) { + document.removeEventListener("contextmenu", handleContextMenu, true) + } }) })