Skip to content

Commit

Permalink
fix(core): properly check if document is loaded, closes #2716 (#2900)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Nov 16, 2021
1 parent 15164d9 commit 000d126
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-ready-check.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Properly check if document is loaded before invoking commands.
2 changes: 1 addition & 1 deletion core/tauri/scripts/core.js
Expand Up @@ -52,7 +52,7 @@
return reject(new Error('Invalid argument type.'))
}

if (window.__TAURI_POST_MESSAGE__) {
if (document.readyState === 'complete' || document.readyState === 'interactive') {
window.__TAURI_POST_MESSAGE__(
cmd, {
...args,
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/manager.rs
Expand Up @@ -509,7 +509,7 @@ impl<R: Runtime> WindowManager<R> {
r#"
{core_script}
{event_initialization_script}
if (window.__TAURI_INVOKE__) {{
if (document.readyState === 'complete') {{
window.__TAURI_INVOKE__("__initialized", {{ url: window.location.href }}, {key})
}} else {{
window.addEventListener('DOMContentLoaded', function () {{
Expand Down

0 comments on commit 000d126

Please sign in to comment.