Skip to content

Commit c14b1df

Browse files
0rvaramrbashirlucasfernog
authored
fix(core): Invoke event listener in windows safely to avoid causing uncaught errors in windows that have loaded external urls (#5563)
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com> Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 41a471b commit c14b1df

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed
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+
Invoke event listener in windows safely to avoid causing uncaught errors in windows that have loaded external urls

core/tauri/src/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ fn on_window_event<R: Runtime>(
14081408
let windows = windows_map.values();
14091409
for window in windows {
14101410
window.eval(&format!(
1411-
r#"window.__TAURI_METADATA__.__windows = window.__TAURI_METADATA__.__windows.filter(w => w.label !== "{}");"#,
1411+
r#"(function () {{ const metadata = window.__TAURI_METADATA__; if (metadata != null) {{ metadata.__windows = window.__TAURI_METADATA__.__windows.filter(w => w.label !== "{}"); }} }})()"#,
14121412
label
14131413
))?;
14141414
}

core/tauri/src/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ impl<R: Runtime> Window<R> {
14561456
payload: S,
14571457
) -> crate::Result<()> {
14581458
self.eval(&format!(
1459-
"window['{}']({{event: {}, windowLabel: {}, payload: {}}})",
1459+
"(function () {{ const fn = window['{}']; fn && fn({{event: {}, windowLabel: {}, payload: {}}}) }})()",
14601460
self.manager.event_emit_function_name(),
14611461
serde_json::to_string(event)?,
14621462
serde_json::to_string(&source_window_label)?,

0 commit comments

Comments
 (0)