Skip to main content

Crate tauri_plugin_dev_invoke

Crate tauri_plugin_dev_invoke 

Source
Expand description

Invoke Tauri commands from an ordinary browser during development.

tauri-plugin-dev-invoke starts a small HTTP server next to your app and routes every request through Tauri’s real IPC, so commands run exactly as they do in the webview: all extractors work (tauri::State, tauri::AppHandle, tauri::Window, …), capabilities and permissions are enforced, and plugin commands behave normally.

It also bridges the other direction. Rust pushes values to the frontend by evaluating runCallback inside a webview, which a browser tab can never receive. The plugin injects a small script into the host webview that relays those callbacks back to the dev server, which streams them to the browser. That makes tauri::ipc::Channel, the event system and plugin listeners work in the browser too.

§Example

ⓘ
tauri::Builder::default()
    .plugin(tauri_plugin_dev_invoke::init())
    .run(tauri::generate_context!())
    .expect("error while running tauri application");

Use Builder to change the port, restrict which browser origins may connect, or pick the window that browser requests impersonate:

ⓘ
tauri::Builder::default()
    .plugin(
        tauri_plugin_dev_invoke::Builder::new()
            .port(4000)
            .window("main")
            .allow_origin("http://localhost:5173")
            .build(),
    )
    .run(tauri::generate_context!())
    .expect("error while running tauri application");

Every one of those can also be set at launch, which is how you run several dev instances of the same binary side by side:

DEV_INVOKE_PORT=3031 npm run tauri dev
VariableOverrides
DEV_INVOKE_HOSTBuilder::host — an IP address, or localhost
DEV_INVOKE_PORTBuilder::port
DEV_INVOKE_ALLOWED_ORIGINSBuilder::allowed_origins — comma-separated, or * for any
DEV_INVOKE_HEADLESSBuilder::headless — 1/true/yes/on, or the negatives

The environment wins over the builder, so a hard-coded .port() can still be overridden at launch. A value that does not parse is reported on stderr and ignored.

§Security

The server only starts in debug builds. In a release build it is compiled out entirely unless you enable the allow-in-release cargo feature and call Builder::enabled_in_release.

It binds to 127.0.0.1 and, by default, only answers browser requests coming from your build.devUrl origin. Anything reachable through the server can run any command your app exposes, so keep it on loopback and keep the origin list tight.

Structs§

Builder
Configures the plugin.
Config
Runtime configuration of the dev server. Build one with Builder.

Enums§

OriginPolicy
Which browser origins are allowed to talk to the dev server.

Constants§

DEFAULT_PORT
Default TCP port the dev server listens on.

Functions§

init
Initializes the plugin with the default configuration.