Skip to content

Commit

Permalink
fix(core): Invoke event listener in windows safely to avoid causing u…
Browse files Browse the repository at this point in the history
…ncaught 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>
  • Loading branch information
3 people committed Dec 8, 2022
1 parent 41a471b commit c14b1df
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/avoid-errors-in-external-urled-windows.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Invoke event listener in windows safely to avoid causing uncaught errors in windows that have loaded external urls
2 changes: 1 addition & 1 deletion core/tauri/src/manager.rs
Expand Up @@ -1408,7 +1408,7 @@ fn on_window_event<R: Runtime>(
let windows = windows_map.values();
for window in windows {
window.eval(&format!(
r#"window.__TAURI_METADATA__.__windows = window.__TAURI_METADATA__.__windows.filter(w => w.label !== "{}");"#,
r#"(function () {{ const metadata = window.__TAURI_METADATA__; if (metadata != null) {{ metadata.__windows = window.__TAURI_METADATA__.__windows.filter(w => w.label !== "{}"); }} }})()"#,
label
))?;
}
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/window.rs
Expand Up @@ -1456,7 +1456,7 @@ impl<R: Runtime> Window<R> {
payload: S,
) -> crate::Result<()> {
self.eval(&format!(
"window['{}']({{event: {}, windowLabel: {}, payload: {}}})",
"(function () {{ const fn = window['{}']; fn && fn({{event: {}, windowLabel: {}, payload: {}}}) }})()",
self.manager.event_emit_function_name(),
serde_json::to_string(event)?,
serde_json::to_string(&source_window_label)?,
Expand Down

0 comments on commit c14b1df

Please sign in to comment.