Skip to content

Commit 079b1cc

Browse files
authored
fix(core): properly get external URL origin, closes #4414 (#4417)
1 parent f1d9982 commit 079b1cc

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

.changes/fix-dev-path-origin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Initialize Tauri script when `devPath` is an external URL with path.

core/tauri/src/hooks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(crate) struct IpcJavascript<'a> {
3939
#[derive(Template)]
4040
#[default_template("../scripts/isolation.js")]
4141
pub(crate) struct IsolationJavascript<'a> {
42-
pub(crate) origin: &'a str,
42+
pub(crate) origin: String,
4343
pub(crate) isolation_src: &'a str,
4444
pub(crate) style: &'a str,
4545
}

core/tauri/src/manager.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,16 +362,10 @@ impl<R: Runtime> WindowManager<R> {
362362
}
363363

364364
/// Get the origin as it will be seen in the webview.
365-
fn get_browser_origin(&self) -> Cow<'_, str> {
365+
fn get_browser_origin(&self) -> String {
366366
match self.base_path() {
367-
AppUrl::Url(WindowUrl::External(url)) => {
368-
let mut url = url.to_string();
369-
if url.ends_with('/') {
370-
url.pop();
371-
}
372-
Cow::Owned(url)
373-
}
374-
_ => Cow::Owned(format_real_schema("tauri")),
367+
AppUrl::Url(WindowUrl::External(url)) => url.origin().ascii_serialization(),
368+
_ => format_real_schema("tauri"),
375369
}
376370
}
377371

@@ -450,7 +444,7 @@ impl<R: Runtime> WindowManager<R> {
450444
if let Pattern::Isolation { schema, .. } = self.pattern() {
451445
webview_attributes = webview_attributes.initialization_script(
452446
&IsolationJavascript {
453-
origin: &self.get_browser_origin(),
447+
origin: self.get_browser_origin(),
454448
isolation_src: &crate::pattern::format_real_schema(schema),
455449
style: tauri_utils::pattern::isolation::IFRAME_STYLE,
456450
}
@@ -883,7 +877,7 @@ impl<R: Runtime> WindowManager<R> {
883877
#[derive(Template)]
884878
#[default_template("../scripts/init.js")]
885879
struct InitJavascript<'a> {
886-
origin: Cow<'a, str>,
880+
origin: String,
887881
#[raw]
888882
pattern_script: &'a str,
889883
#[raw]

0 commit comments

Comments
 (0)