Skip to content

core

Invoke your custom commands.

This package is also accessible with window.__TAURI__.core when app.withGlobalTauri in tauri.conf.json is set to true.

Source: undefined

Type Parameter Default type
T unknown

new Channel<T>(onmessage?): Channel<T>;

Source: undefined

Parameter Type
onmessage? (response) => void

Channel<T>

Property Type Description Defined in
id number The callback id returned from transformCallback Source: undefined

get onmessage(): (response) => void;

Source: undefined

(response) => void

set onmessage(handler): void;

Source: undefined

Parameter Type
handler (response) => void

void

__TAURI_TO_IPC_KEY__(): string;

Source: undefined

string

toJSON(): string;

Source: undefined

string


Source: undefined

new PluginListener(
plugin,
event,
channelId
): PluginListener;

Source: undefined

Parameter Type
plugin string
event string
channelId number

PluginListener

Property Type Defined in
channelId number Source: undefined
event string Source: undefined
plugin string Source: undefined

unregister(): Promise<void>;

Source: undefined

Promise<void>


Source: undefined

A rust-backed resource stored through tauri::Manager::resources_table API.

The resource lives in the main process and does not exist in the Javascript world, and thus will not be cleaned up automatically except on application exit. If you want to clean it up early, call Resource.close or use Explicit Resource Management.

To support older browsers with Explicit Resource Management, use a supported compiler (e.g. tsc) or bundler (e.g. rollup).

import { Resource, invoke } from '@tauri-apps/api/core';
export class DatabaseHandle extends Resource {
static async open(path: string): Promise<DatabaseHandle> {
const rid: number = await invoke('open_db', { path });
return new DatabaseHandle(rid);
}
async execute(sql: string): Promise<void> {
await invoke('execute_sql', { rid: this.rid, sql });
}
}

To use with Explicit Resource Management:

await using db = await DatabaseHandle.open('test.db');
await db.execute('SELECT *');

To support older browsers, add the following to the globals (e.g. adding to the HTML file):

Symbol.dispose ??= Symbol("Symbol.dispose");
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");

And for the compiler, for example tsc, rollup, vite, add the following to tsconfig.json:

{
"compilerOptions": {
"target": "es2022",
"lib": ["es2022", "esnext.disposable", "dom"]
}
}

new Resource(rid): Resource;

Source: undefined

Parameter Type
rid number

Resource

get rid(): number;

Source: undefined

number

asyncDispose: Promise<void>;

Source: undefined

Promise<void>

close(): Promise<void>;

Source: undefined

Destroys and cleans up this resource from memory. You should not call any method on this object anymore and should drop any reference to it.

Promise<void>

Source: undefined

2.0.0

Property Type Defined in
headers HeadersInit Source: undefined

type InvokeArgs =
| Record<string, unknown>
| number[]
| ArrayBuffer
| Uint8Array;

Source: undefined

Command arguments.

1.0.0


type PermissionState = "granted" | "denied" | "prompt" | "prompt-with-rationale";

Source: undefined

const SERIALIZE_TO_IPC_FN: "__TAURI_TO_IPC_KEY__" = '__TAURI_TO_IPC_KEY__';

Source: undefined

A key to be used to implement a special function on your types that define how your type should be serialized when passing across the IPC.

Given a type in Rust that looks like this

#[derive(serde::Serialize, serde::Deserialize)
enum UserId {
String(String),
Number(u32),
}

UserId::String("id") would be serialized into { String: "id" } and so we need to pass the same structure back to Rust

import { SERIALIZE_TO_IPC_FN } from "@tauri-apps/api/core"
class UserIdString {
id
constructor(id) {
this.id = id
}
[SERIALIZE_TO_IPC_FN]() {
return { String: this.id }
}
}
class UserIdNumber {
id
constructor(id) {
this.id = id
}
[SERIALIZE_TO_IPC_FN]() {
return { Number: this.id }
}
}
type UserId = UserIdString | UserIdNumber

function addPluginListener<T>(
plugin,
event,
cb
): Promise<PluginListener>;

Source: undefined

Adds a listener to a plugin event.

Type Parameter
T
Parameter Type
plugin string
event string
cb (payload) => void

Promise<PluginListener>

The listener object to stop listening to the events.

2.0.0


function checkPermissions<T>(plugin): Promise<T>;

Source: undefined

Get permission state for a plugin.

This should be used by plugin authors to wrap their actual implementation.

Type Parameter
T
Parameter Type
plugin string

Promise<T>


function convertFileSrc(filePath, protocol?): string;

Source: undefined

Convert a device file path to a URL that can be loaded by the webview.

The asset protocol must be enabled and the files you want to expose must be included in its scope. The protocol origins must also be allowed by the relevant app.security.csp directive. For example, this configuration allows images from the user’s downloads directory:

{
"app": {
"security": {
"assetProtocol": {
"enable": true,
"scope": ["$DOWNLOAD/**"]
},
"csp": "default-src 'self'; img-src 'self' asset: http://asset.localhost"
}
}
}

See assetProtocol for the available scope variables and platform-specific protocol details.

Parameter Type Default value Description
filePath string undefined The file path.
protocol string 'asset' The protocol to use. Defaults to asset. You only need to set this when using a custom protocol.

string

the URL that can be used as source on the webview.

import { downloadDir, join } from '@tauri-apps/api/path';
import { convertFileSrc } from '@tauri-apps/api/core';
const downloads = await downloadDir();
const filePath = await join(downloads, 'photo.png');
const assetUrl = convertFileSrc(filePath);
const image = document.getElementById('my-image') as HTMLImageElement;
image.src = assetUrl;

1.0.0


function invoke<T>(
cmd,
args?,
options?
): Promise<T>;

Source: undefined

Sends a message to the backend.

Type Parameter
T
Parameter Type Description
cmd string The command name.
args InvokeArgs The optional arguments to pass to the command.
options? InvokeOptions The request options.

Promise<T>

A promise resolving or rejecting to the backend response.

import { invoke } from '@tauri-apps/api/core';
await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });

1.0.0


function isTauri(): boolean;

Source: undefined

boolean


function requestPermissions<T>(plugin): Promise<T>;

Source: undefined

Request permissions.

This should be used by plugin authors to wrap their actual implementation.

Type Parameter
T
Parameter Type
plugin string

Promise<T>


function transformCallback<T>(callback?, once?): number;

Source: undefined

Stores the callback in a known location, and returns an identifier that can be passed to the backend. The backend uses the identifier to eval() the callback.

Type Parameter Default type
T unknown
Parameter Type Default value
callback? (response) => void undefined
once? boolean false

number

An unique identifier associated with the callback function.

1.0.0


© 2026 Tauri Contributors. CC-BY / MIT