diff --git a/.changes/core-unix-window-data-url.md b/.changes/core-unix-window-data-url.md new file mode 100644 index 000000000..1bce04f7a --- /dev/null +++ b/.changes/core-unix-window-data-url.md @@ -0,0 +1,5 @@ +--- +'tauri': 'patch:bug' +--- + +On macOS and Linux, fix app crashing when creating a window with `data:` uri. diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index df16067ac..b525f3fcb 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -471,21 +471,21 @@ impl WindowManager { } let window_url = Url::parse(&pending.url).unwrap(); - let window_origin = - if cfg!(windows) && window_url.scheme() != "http" && window_url.scheme() != "https" { - format!("https://{}.localhost", window_url.scheme()) - } else { - format!( - "{}://{}{}", - window_url.scheme(), - window_url.host().unwrap(), - if let Some(port) = window_url.port() { - format!(":{port}") - } else { - "".into() - } - ) - }; + let window_origin = if window_url.scheme() == "data" { + "null".into() + } else if cfg!(windows) && window_url.scheme() != "http" && window_url.scheme() != "https" { + format!("https://{}.localhost", window_url.scheme()) + } else { + format!( + "{}://{}{}", + window_url.scheme(), + window_url.host().unwrap(), + window_url + .port() + .map(|p| format!(":{p}")) + .unwrap_or_default() + ) + }; if !registered_scheme_protocols.contains(&"tauri".into()) { let web_resource_request_handler = pending.web_resource_request_handler.take();