diff --git a/.changes/fix-ready-check.md b/.changes/fix-ready-check.md new file mode 100644 index 00000000000..02ddcf78d15 --- /dev/null +++ b/.changes/fix-ready-check.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Properly check if document is loaded before invoking commands. diff --git a/core/tauri/scripts/core.js b/core/tauri/scripts/core.js index fdae434797b..7dffe652e96 100644 --- a/core/tauri/scripts/core.js +++ b/core/tauri/scripts/core.js @@ -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, diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index 340b63aa7b4..d328300982b 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -509,7 +509,7 @@ impl WindowManager { 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 () {{