-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
Describe the bug
The examples do not work, at least for me on Windows.
Reproduction
git clone https://github.com/tauri-apps/tauri.git && cd tauricargo run --example helloworld- Type something and submit the form.
2025-03-15-bXIKVfHYnq.mp4
Expected behavior
The "Hello from Rust" message appears
Full tauri info output
Tauri repo b05f82d35ba068bfeb44193b204fbfe365415a25
Stack trace
Additional context
If I open dev tools and refresh the window, then it starts working.
Looks like with_global_tauri utilizes with_initialization_script
tauri/crates/tauri/src/manager/webview.rs
Lines 377 to 405 in 95fc3cd
| let bundle_script = if with_global_tauri { | |
| include_str!("../../scripts/bundle.global.js") | |
| } else { | |
| "" | |
| }; | |
| let freeze_prototype = if app_manager.config.app.security.freeze_prototype { | |
| include_str!("../../scripts/freeze_prototype.js") | |
| } else { | |
| "" | |
| }; | |
| InitJavascript { | |
| pattern_script, | |
| ipc_script, | |
| bundle_script, | |
| core_script: &CoreJavascript { | |
| os_name: std::env::consts::OS, | |
| protocol_scheme: if use_https_scheme { "https" } else { "http" }, | |
| invoke_key: self.invoke_key(), | |
| } | |
| .render_default(&Default::default())? | |
| .into_string(), | |
| event_initialization_script: &crate::event::event_initialization_script( | |
| app_manager.listeners().function_name(), | |
| app_manager.listeners().listeners_object_name(), | |
| ), | |
| freeze_prototype, | |
| } |
tauri/crates/tauri-runtime-wry/src/lib.rs
Line 4532 in cedb24d
| webview_builder = webview_builder.with_initialization_script(&script); |
But its docs state
It is guaranteed that code is executed before
window.onload.
I considered just adding a docstring to withGlobalTauri mentioning the fact that you have to wait for onload to finish before using it, but then I saw that we have docs on this https://v2.tauri.app/develop/calling-rust/#basic-example, and the docs don't say anything about onload.