JavaScript API
The tauri-remote-ui npm package mirrors the relevant parts of @tauri-apps/api
with shims that work both inside the Tauri webview and over the remote WebSocket
transport. Import from the per-area entry points:
import { invoke } from "tauri-remote-ui/api/core";import { listen, latencyMs } from "tauri-remote-ui/api/event";import { getVersion } from "tauri-remote-ui/api/app";tauri-remote-ui/api/core
Section titled “tauri-remote-ui/api/core”invoke
Section titled “invoke”function invoke<T>(cmd: string, args?: InvokeArgs, options?: InvokeOptions): Promise<T>Invokes a Tauri command. Native IPC when available; otherwise sends the request over the WebSocket and resolves with the result.
- Rejects with the command’s error on failure.
- Rejects with a timeout error if no response arrives within 30 seconds.
- Throws if neither native IPC nor an open WebSocket is available.
const result = await invoke<number>("increment");tauri-remote-ui/api/event
Section titled “tauri-remote-ui/api/event”listen
Section titled “listen”function listen<T>(event: EventName, handler: EventCallback<T>, options?: Options): Promise<UnlistenFn>Subscribes to an event. Native listener when inside Tauri; otherwise backed by a
WebSocket-fed EventTarget. Returns an unlisten function.
const unlisten = await listen<{ result: number }>("counter", (e) => { console.log(e.payload.result);});// laterunlisten();latencyMs
Section titled “latencyMs”let latencyMs: numberThe most recent WebSocket round-trip latency in milliseconds, updated by the ping/pong heartbeat (every 10 s). Useful for surfacing connection quality in your UI; values above 200 ms also log a console warning.
import { latencyMs } from "tauri-remote-ui/api/event";console.log(`round trip: ${latencyMs} ms`);UnlistenFn
Section titled “UnlistenFn”Re-exported from @tauri-apps/api/event for convenience.
tauri-remote-ui/api/app
Section titled “tauri-remote-ui/api/app”Application-metadata helpers mirroring @tauri-apps/api/app, routed through the
remote-aware invoke. Includes getVersion, getName, getTauriVersion,
getIdentifier, show, hide, defaultWindowIcon, setTheme,
setDockVisibility, getBundleType, and more.
import { getVersion, getName } from "tauri-remote-ui/api/app";
const [version, name] = await Promise.all([getVersion(), getName()]);Detecting the environment
Section titled “Detecting the environment”To branch on where your UI is running:
const isDesktop = typeof window !== "undefined" && Boolean((window as any).__TAURI_INTERNALS__ || (window as any).__TAURI__);This is exactly the check the shims use internally to decide between native IPC and the WebSocket bridge.