From 37d075fbb3aaa192e9e896d01f7e669fae69a880 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Wed, 28 Jan 2026 19:41:39 +0000 Subject: [PATCH] fix(tauri): allow tauri.localhost internal navigation --- packages/tauri-app/src-tauri/capabilities/main-window.json | 2 +- packages/tauri-app/src-tauri/gen/schemas/capabilities.json | 2 +- packages/tauri-app/src-tauri/src/main.rs | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/tauri-app/src-tauri/capabilities/main-window.json b/packages/tauri-app/src-tauri/capabilities/main-window.json index 61d6e346..14cb2d7f 100644 --- a/packages/tauri-app/src-tauri/capabilities/main-window.json +++ b/packages/tauri-app/src-tauri/capabilities/main-window.json @@ -3,7 +3,7 @@ "identifier": "main-window-native-dialogs", "description": "Grant the main window access to required core features and native dialog commands.", "remote": { - "urls": ["http://127.0.0.1:*", "http://localhost:*"] + "urls": ["http://127.0.0.1:*", "http://localhost:*", "http://tauri.localhost/*", "https://tauri.localhost/*"] }, "windows": ["main"], "permissions": [ diff --git a/packages/tauri-app/src-tauri/gen/schemas/capabilities.json b/packages/tauri-app/src-tauri/gen/schemas/capabilities.json index c98bf3f4..1e38e0c9 100644 --- a/packages/tauri-app/src-tauri/gen/schemas/capabilities.json +++ b/packages/tauri-app/src-tauri/gen/schemas/capabilities.json @@ -1 +1 @@ -{"main-window-native-dialogs":{"identifier":"main-window-native-dialogs","description":"Grant the main window access to required core features and native dialog commands.","remote":{"urls":["http://127.0.0.1:*","http://localhost:*"]},"local":true,"windows":["main"],"permissions":["core:default","core:menu:default","dialog:allow-open","opener:allow-default-urls","core:webview:allow-set-webview-zoom"]}} \ No newline at end of file +{"main-window-native-dialogs":{"identifier":"main-window-native-dialogs","description":"Grant the main window access to required core features and native dialog commands.","remote":{"urls":["http://127.0.0.1:*","http://localhost:*","http://tauri.localhost/*","https://tauri.localhost/*"]},"local":true,"windows":["main"],"permissions":["core:default","core:menu:default","dialog:allow-open","opener:allow-default-urls","core:webview:allow-set-webview-zoom"]}} \ No newline at end of file diff --git a/packages/tauri-app/src-tauri/src/main.rs b/packages/tauri-app/src-tauri/src/main.rs index 81645233..1748a07a 100644 --- a/packages/tauri-app/src-tauri/src/main.rs +++ b/packages/tauri-app/src-tauri/src/main.rs @@ -39,7 +39,10 @@ fn is_dev_mode() -> bool { fn should_allow_internal(url: &Url) -> bool { match url.scheme() { "tauri" | "asset" | "file" => true, - "http" | "https" => matches!(url.host_str(), Some("127.0.0.1" | "localhost")), + // On Windows/WebView2, Tauri serves the app assets from `tauri.localhost`. + // This must be treated as an internal origin or the navigation guard will + // redirect it to the system browser and the app will appear blank. + "http" | "https" => matches!(url.host_str(), Some("127.0.0.1" | "localhost" | "tauri.localhost")), _ => false, } }