Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add way to check if Tauri's initialization scripts have run #12348

Open
alexmoon opened this issue Jan 10, 2025 · 0 comments · May be fixed by #12586
Open

[feat] Add way to check if Tauri's initialization scripts have run #12348

alexmoon opened this issue Jan 10, 2025 · 0 comments · May be fixed by #12586

Comments

@alexmoon
Copy link
Contributor

Describe the problem

Tauri's initialization scripts may not have executed when the webview starts executing user scripts. This can cause Tauri API calls to fail unexpectedly. For example calling await listen(...) at a top level will fail if the __TAURI_INTERNALS__ object has not yet been populated.

Describe the solution you'd like

I would like to be able to check if Tauri has finished initializing and wait if it has not. I would suggest a new variable like window.__TAURI_READY__ or window.__TAURI_INTERNALS__.ready which would be set to true after all initialization scripts have finished executing. That could be wrapped in an function in the core library like:

function isReady(): bool {
  return window.__TAURI_INTERNALS__?.ready ?? false;
}

Additionally, it would be nice to dispatch an event after the ready flag is set like window.dispatchEvent("tauriReady", new Event()) so that a script can wait for the ready condition without having to poll.

Alternatives considered

No response

Additional context

See https://discord.com/channels/616186924390023171/1327342177608794113 for discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant