diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index b7409b5c9..b3b0ffc40 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -377,13 +377,17 @@ impl WindowManager { pub(crate) fn get_url(&self) -> Cow<'_, Url> { match self.base_path() { AppUrl::Url(WindowUrl::External(url)) => Cow::Borrowed(url), - #[cfg(windows)] - _ => Cow::Owned(Url::parse("https://tauri.localhost").unwrap()), - #[cfg(not(windows))] - _ => Cow::Owned(Url::parse("tauri://localhost").unwrap()), + _ => self.protocol_url(), } } + pub(crate) fn protocol_url(&self) -> Cow<'_, Url> { + #[cfg(any(window, target_os = "android"))] + return Cow::Owned(Url::parse("https://tauri.localhost").unwrap()); + #[cfg(not(any(window, target_os = "android")))] + Cow::Owned(Url::parse("tauri://localhost").unwrap()) + } + fn csp(&self) -> Option { if cfg!(feature = "custom-protocol") { self.inner.config.tauri.security.csp.clone() diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 383d6f329..e7b87a92a 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -1653,13 +1653,18 @@ impl Window { self.current_url = url; } + fn is_local_url(&self, current_url: &Url) -> bool { + self.manager.get_url().make_relative(current_url).is_some() || { + let protocol_url = self.manager.protocol_url(); + current_url.scheme() == protocol_url.scheme() && current_url.domain() == protocol_url.domain() + } + } + /// Handles this window receiving an [`InvokeMessage`]. pub fn on_message(self, payload: InvokePayload) -> crate::Result<()> { let manager = self.manager.clone(); let current_url = self.url(); - let config_url = manager.get_url(); - let is_local = - config_url.make_relative(¤t_url).is_some() || current_url.scheme() == "tauri"; + let is_local = self.is_local_url(¤t_url); let mut scope_not_found_error_message = ipc_scope_not_found_error_message(&self.window.label, current_url.as_str());