Forráskód Böngészése

fix(core): properly check if document is loaded, closes #2716 (#2900)

Lucas Fernandes Nogueira 3 éve
szülő
commit
000d126e0e

+ 5 - 0
.changes/fix-ready-check.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Properly check if document is loaded before invoking commands.

+ 1 - 1
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,

+ 1 - 1
core/tauri/src/manager.rs

@@ -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 () {{