mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-11 07:55:34 +03:00
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>
This commit is contained in:
parent
41a471b23a
commit
c14b1df372
5
.changes/avoid-errors-in-external-urled-windows.md
Normal file
5
.changes/avoid-errors-in-external-urled-windows.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Invoke event listener in windows safely to avoid causing uncaught errors in windows that have loaded external urls
|
@ -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
|
||||
))?;
|
||||
}
|
||||
|
@ -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)?,
|
||||
|
Loading…
Reference in New Issue
Block a user