Browse Source

fix(core): properly get external URL origin, closes #4414 (#4417)

Lucas Fernandes Nogueira 3 years ago
parent
commit
079b1cc06e
3 changed files with 11 additions and 12 deletions
  1. 5 0
      .changes/fix-dev-path-origin.md
  2. 1 1
      core/tauri/src/hooks.rs
  3. 5 11
      core/tauri/src/manager.rs

+ 5 - 0
.changes/fix-dev-path-origin.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Initialize Tauri script when `devPath` is an external URL with path.

+ 1 - 1
core/tauri/src/hooks.rs

@@ -39,7 +39,7 @@ pub(crate) struct IpcJavascript<'a> {
 #[derive(Template)]
 #[default_template("../scripts/isolation.js")]
 pub(crate) struct IsolationJavascript<'a> {
-  pub(crate) origin: &'a str,
+  pub(crate) origin: String,
   pub(crate) isolation_src: &'a str,
   pub(crate) style: &'a str,
 }

+ 5 - 11
core/tauri/src/manager.rs

@@ -362,16 +362,10 @@ impl<R: Runtime> WindowManager<R> {
   }
 
   /// Get the origin as it will be seen in the webview.
-  fn get_browser_origin(&self) -> Cow<'_, str> {
+  fn get_browser_origin(&self) -> String {
     match self.base_path() {
-      AppUrl::Url(WindowUrl::External(url)) => {
-        let mut url = url.to_string();
-        if url.ends_with('/') {
-          url.pop();
-        }
-        Cow::Owned(url)
-      }
-      _ => Cow::Owned(format_real_schema("tauri")),
+      AppUrl::Url(WindowUrl::External(url)) => url.origin().ascii_serialization(),
+      _ => format_real_schema("tauri"),
     }
   }
 
@@ -450,7 +444,7 @@ impl<R: Runtime> WindowManager<R> {
     if let Pattern::Isolation { schema, .. } = self.pattern() {
       webview_attributes = webview_attributes.initialization_script(
         &IsolationJavascript {
-          origin: &self.get_browser_origin(),
+          origin: self.get_browser_origin(),
           isolation_src: &crate::pattern::format_real_schema(schema),
           style: tauri_utils::pattern::isolation::IFRAME_STYLE,
         }
@@ -883,7 +877,7 @@ impl<R: Runtime> WindowManager<R> {
     #[derive(Template)]
     #[default_template("../scripts/init.js")]
     struct InitJavascript<'a> {
-      origin: Cow<'a, str>,
+      origin: String,
       #[raw]
       pattern_script: &'a str,
       #[raw]