Skip to content

Commit 000d126

Browse files
authored
fix(core): properly check if document is loaded, closes #2716 (#2900)
1 parent 15164d9 commit 000d126

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

.changes/fix-ready-check.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+
Properly check if document is loaded before invoking commands.

core/tauri/scripts/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
return reject(new Error('Invalid argument type.'))
5353
}
5454

55-
if (window.__TAURI_POST_MESSAGE__) {
55+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
5656
window.__TAURI_POST_MESSAGE__(
5757
cmd, {
5858
...args,

core/tauri/src/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ impl<R: Runtime> WindowManager<R> {
509509
r#"
510510
{core_script}
511511
{event_initialization_script}
512-
if (window.__TAURI_INVOKE__) {{
512+
if (document.readyState === 'complete') {{
513513
window.__TAURI_INVOKE__("__initialized", {{ url: window.location.href }}, {key})
514514
}} else {{
515515
window.addEventListener('DOMContentLoaded', function () {{

0 commit comments

Comments
 (0)