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

This commit is contained in:
Lucas Fernandes Nogueira
2022-06-21 05:29:03 -07:00
committed by GitHub
parent f1d998243a
commit 079b1cc06e
3 changed files with 11 additions and 12 deletions

View File

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

View File

@@ -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,
}

View File

@@ -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]