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.
Classes
Section titled “Classes”Channel<T>
Section titled “Channel<T>”Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
T | unknown |
Constructors
Section titled “Constructors”new Channel()
Section titled “new Channel()”new Channel<T>(onmessage?): Channel<T>Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
onmessage? | (response) => void |
Returns
Section titled “Returns”Channel<T>
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L87
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
id | number | The callback id returned from transformCallback | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L79 |
Accessors
Section titled “Accessors”onmessage
Section titled “onmessage”get onmessage(): (response) => voidset onmessage(handler): voidParameters
Section titled “Parameters”| Parameter | Type |
|---|---|
handler | (response) => void |
Returns
Section titled “Returns”Function
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
response | T |
Returns
Section titled “Returns”void
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L142
Methods
Section titled “Methods”__TAURI_TO_IPC_KEY__()
Section titled “__TAURI_TO_IPC_KEY__()”__TAURI_TO_IPC_KEY__(): stringReturns
Section titled “Returns”string
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L146
toJSON()
Section titled “toJSON()”toJSON(): stringReturns
Section titled “Returns”string
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L150
PluginListener
Section titled “PluginListener”Constructors
Section titled “Constructors”new PluginListener()
Section titled “new PluginListener()”new PluginListener( plugin, event, channelId): PluginListenerParameters
Section titled “Parameters”| Parameter | Type |
|---|---|
plugin | string |
event | string |
channelId | number |
Returns
Section titled “Returns”Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L161
Properties
Section titled “Properties”| Property | Type | Defined in |
|---|---|---|
channelId | number | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L159 |
event | string | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L158 |
plugin | string | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L157 |
Methods
Section titled “Methods”unregister()
Section titled “unregister()”unregister(): Promise<void>Returns
Section titled “Returns”Promise<void>
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L167
Resource
Section titled “Resource”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
Example
Section titled “Example”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 }); }}Extended by
Section titled “Extended by”Constructors
Section titled “Constructors”new Resource()
Section titled “new Resource()”new Resource(rid): ResourceParameters
Section titled “Parameters”| Parameter | Type |
|---|---|
rid | number |
Returns
Section titled “Returns”Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L322
Accessors
Section titled “Accessors”get rid(): numberReturns
Section titled “Returns”number
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L318
Methods
Section titled “Methods”close()
Section titled “close()”close(): Promise<void>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.
Returns
Section titled “Returns”Promise<void>
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L330
Interfaces
Section titled “Interfaces”InvokeOptions
Section titled “InvokeOptions”2.0.0
Properties
Section titled “Properties”| Property | Type | Defined in |
|---|---|---|
headers | HeadersInit | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L233 |
Type Aliases
Section titled “Type Aliases”InvokeArgs
Section titled “InvokeArgs”type InvokeArgs: Record<string, unknown> | number[] | ArrayBuffer | Uint8Array;Command arguments.
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L227
PermissionState
Section titled “PermissionState”type PermissionState: "granted" | "denied" | "prompt" | "prompt-with-rationale";Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L202
Variables
Section titled “Variables”SERIALIZE_TO_IPC_FN
Section titled “SERIALIZE_TO_IPC_FN”const SERIALIZE_TO_IPC_FN: "__TAURI_TO_IPC_KEY__" = '__TAURI_TO_IPC_KEY__';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.
Example
Section titled “Example”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 | UserIdNumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L59
Functions
Section titled “Functions”addPluginListener()
Section titled “addPluginListener()”function addPluginListener<T>( plugin, event,cb): Promise<PluginListener>Adds a listener to a plugin event.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
plugin | string |
event | string |
cb | (payload) => void |
Returns
Section titled “Returns”The listener object to stop listening to the events.
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L182
checkPermissions()
Section titled “checkPermissions()”function checkPermissions<T>(plugin): Promise<T>Get permission state for a plugin.
This should be used by plugin authors to wrap their actual implementation.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
plugin | string |
Returns
Section titled “Returns”Promise<T>
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L209
convertFileSrc()
Section titled “convertFileSrc()”function convertFileSrc(filePath, protocol): stringConvert a device file path to an URL that can be loaded by the webview.
Note that asset: and http://asset.localhost must be added to app.security.csp in tauri.conf.json.
Example CSP value: "csp": "default-src 'self' ipc: http://ipc.localhost; img-src 'self' asset: http://asset.localhost" to use the asset protocol on image sources.
Additionally, "enable" : "true" must be added to app.security.assetProtocol
in tauri.conf.json and its access scope must be defined on the scope array on the same assetProtocol object.
Parameters
Section titled “Parameters”| 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. |
Returns
Section titled “Returns”string
the URL that can be used as source on the webview.
Example
Section titled “Example”import { appDataDir, join } from '@tauri-apps/api/path';import { convertFileSrc } from '@tauri-apps/api/core';const appDataDirPath = await appDataDir();const filePath = await join(appDataDirPath, 'assets/video.mp4');const assetUrl = convertFileSrc(filePath);
const video = document.getElementById('my-video');const source = document.createElement('source');source.type = 'video/mp4';source.src = assetUrl;video.appendChild(source);video.load();1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L289
invoke()
Section titled “invoke()”function invoke<T>( cmd, args,options?): Promise<T>Sends a message to the backend.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
cmd | string | The command name. |
args | InvokeArgs | The optional arguments to pass to the command. |
options? | InvokeOptions | The request options. |
Returns
Section titled “Returns”Promise<T>
A promise resolving or rejecting to the backend response.
Example
Section titled “Example”import { invoke } from '@tauri-apps/api/core';await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L251
isTauri()
Section titled “isTauri()”function isTauri(): booleanReturns
Section titled “Returns”boolean
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L337
requestPermissions()
Section titled “requestPermissions()”function requestPermissions<T>(plugin): Promise<T>Request permissions.
This should be used by plugin authors to wrap their actual implementation.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
plugin | string |
Returns
Section titled “Returns”Promise<T>
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L218
transformCallback()
Section titled “transformCallback()”function transformCallback<T>(callback?, once?): numberStores 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 Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
callback? | (response) => void | undefined |
once? | boolean | false |
Returns
Section titled “Returns”number
An unique identifier associated with the callback function.
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L69
© 2026 Tauri Contributors. CC-BY / MIT