Skip to content

Commit

Permalink
fix(core): properly get external URL origin, closes #4414 (#4417)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jun 21, 2022
1 parent f1d9982 commit 079b1cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-dev-path-origin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Initialize Tauri script when `devPath` is an external URL with path.
2 changes: 1 addition & 1 deletion core/tauri/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
16 changes: 5 additions & 11 deletions core/tauri/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}

Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 079b1cc

Please sign in to comment.