From d56a7fc7f7d0575061da9ecd70ba23a5ee0bf8e2 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Mon, 13 Dec 2021 14:37:37 -0300 Subject: [PATCH] fix: asset protocol CORS on Windows --- core/tauri/src/manager.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index 909dc5d62..f3b519117 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -304,16 +304,21 @@ impl WindowManager { } if !registered_scheme_protocols.contains(&"asset".into()) { let window_url = Url::parse(&pending.url).unwrap(); - let window_origin = format!( - "{}://{}{}", - window_url.scheme(), - window_url.host().unwrap(), - if let Some(port) = window_url.port() { - format!(":{}", port) + let window_origin = + if cfg!(windows) && window_url.scheme() != "http" && window_url.scheme() != "https" { + format!("https://{}.localhost", window_url.scheme()) } else { - "".into() - } - ); + format!( + "{}://{}{}", + window_url.scheme(), + window_url.host().unwrap(), + if let Some(port) = window_url.port() { + format!(":{}", port) + } else { + "".into() + } + ) + }; pending.register_uri_scheme_protocol("asset", move |request| { #[cfg(target_os = "windows")] let path = request.uri().replace("asset://localhost/", "");