Skip to content

[bug] Windows: withGlobalTauri: true: window.__TAURI__ is undefined while executing top-level scripts: the examples are broken #12990

@WofWca

Description

@WofWca

Describe the bug

The examples do not work, at least for me on Windows.

Reproduction

  1. git clone https://github.com/tauri-apps/tauri.git && cd tauri
  2. cargo run --example helloworld
  3. 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

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,
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform: Windowsstatus: upstreamThis issue is blocked by upstream dependencies and we need to wait or contribute upstream fixestype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions