Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 39 ยท Plugins and Native Features

The Tauri Plugin System

Learn how Tauri 2 plugins extend your app with native features: installing, registering in Rust, importing the JavaScript API and granting permissions. Includes runnable stand-ins.

The Tauri core is deliberately small. It opens windows, runs your web frontend in the system webview and carries messages between JavaScript and Rust. Almost everything else you might want from a desktop app, such as reading files, showing dialogs, sending notifications or checking for updates, lives in plugins. This keeps your app small, because you only compile what you use, and it keeps your app safe, because every plugin has to be switched on and given permissions before the frontend can touch it.

In this lesson you will learn what a plugin is made of, how to add one, and how a request from JavaScript travels to the plugin and back. The rest of this chapter then uses the official plugins one by one, and Writing a Custom Plugin shows how to build your own.

Real versus stand-in. Tauri needs a Rust toolchain and the system webview, so it cannot run on this site. The bash, rust, json and ts blocks are real code to read and copy. The runnable node blocks are small stand-ins that re-create the idea (a registry of plugins, permission checks, message routing) so you can experiment with it. They are not Tauri.

What a plugin is made of

An official plugin such as the file system plugin has up to four parts:

  1. A Rust crate (tauri-plugin-fs) that registers commands and does the real work.
  2. An npm package (@tauri-apps/plugin-fs) with typed JavaScript functions that call those commands.
  3. Permissions, small named switches such as fs:allow-read-text-file, defined by the plugin and granted in your capability files.
  4. Optional mobile code in Kotlin and Swift, for plugins that need Android or iOS APIs.

Official plugins live in the tauri-apps/plugins-workspace repository. Here are some you will meet in this course:

Plugin What it does
fs Read and write files and folders
dialog Native open/save/message dialogs
store Persistent key-value storage in a JSON file
sql SQLite, MySQL and Postgres through sqlx
notification System notifications
clipboard-manager Read and write the clipboard
global-shortcut Keyboard shortcuts that work when the app is unfocused
opener Open files and URLs with the default app
os, process Platform info, exit and relaunch
http HTTP client that runs in Rust
updater In-app updates (see Updater and Releases)
window-state, single-instance, autostart, deep-link, log Everyday app behavior

Adding a plugin

The Tauri CLI can do every step for you. This adds the Rust crate, the npm package and a starter permission in one go:

Terminal
npm run tauri add fs

If you prefer to do it by hand, there are three steps. First the Rust dependency:

Terminal
cargo add tauri-plugin-fs --manifest-path src-tauri/Cargo.toml

Second, register the plugin when the app is built, in src-tauri/src/lib.rs:

Rust
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_fs::init())
        .plugin(tauri_plugin_dialog::init())
        .run(tauri::generate_context!())
        .expect("error while running the app");
}

Third, install the JavaScript package and grant a permission:

Terminal
npm install @tauri-apps/plugin-fs
JSON
{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "main-capability",
  "windows": ["main"],
  "permissions": ["core:default", "fs:default"]
}

Now the frontend can call the plugin:

TypeScript
import { readTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';

const text = await readTextFile('notes.txt', { baseDir: BaseDirectory.AppData });

If you forget step two, the call fails because the plugin is not registered. If you forget step three, the call fails because it is not allowed. Both errors show up in the browser console, and the second one mentions the missing permission by name, which makes it easy to fix.

How a plugin call travels

Every plugin command is reached through Tauri's message channel, called IPC (inter-process communication). The npm package builds a command name of the form plugin:<name>|<command>, sends it with its arguments, and Tauri checks permissions before it reaches Rust.

sequenceDiagram
  participant JS as Frontend (webview)
  participant Core as Tauri core
  participant Perm as Permission check
  participant Plugin as Plugin (Rust)
  JS->>Core: invoke("plugin:fs|read_text_file", args)
  Core->>Perm: is fs:allow-read-text-file granted to this window?
  Perm-->>Core: yes / no
  Core->>Plugin: run command
  Plugin-->>JS: result or error

A denied permission stops the request before any plugin code runs.

The stand-in below builds exactly this flow in a few lines. It has a registry, one plugin with two commands, and a capability list that decides which commands a window may call.

Node.js Stand-in: a plugin registry with permission checks

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Try granting fs:allow-write-text-file and run it again. The write succeeds, which is how a capability file changes what your frontend may do.

Default permission sets

Granting dozens of small permissions one by one would be tiring, so each plugin ships a default permission set. For example fs:default allows reading app-specific folders but nothing dangerous. You can then add or remove individual permissions on top. The full story, including deny- permissions and scopes, is in Capabilities and Permissions.

Plugin lifecycle hooks

Plugins can also run Rust code when the app starts or stops. A plugin can:

  • Run a setup function when the app builds, for example to open a database.
  • Add managed state with app.manage(...) that commands can read.
  • React to window events, app exit and navigation, and even block navigation.
  • Expose its own invoke_handler commands and emit events to the frontend.

The next stand-in models the lifecycle: plugins are set up in the order you registered them, and torn down in reverse order when the app exits. That ordering is a good habit to keep in mind when one plugin depends on another.

Node.js Stand-in: plugin lifecycle order

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Choosing plugins wisely

  • Add a plugin only when you need it. Each one adds compile time, binary size and attack surface.
  • Prefer the official plugins; community plugins are listed in the Awesome Tauri collection, but read their permissions before trusting them.
  • Plugins that need a system dialog or filesystem access do not bypass the permission system; you still grant them per window.
  • Some plugins are desktop only. Guard them with #[cfg(desktop)] so your mobile build still compiles (see Mobile Development).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which two places must you change on the Rust and capability side before the frontend can use the dialog plugin?

    The plugin must be registered in the Rust builder and its permissions must be granted in a capability file. The npm package alone only provides the JavaScript wrapper.
  2. 2. What does a plugin command name look like on the IPC channel?

    Tauri routes plugin commands as plugin:<name>|<command>, for example plugin:fs|read_text_file.
  3. 3. A call fails with a message that a permission is not allowed. What is the most likely fix?

    Permission errors name the missing permission. Granting it in src-tauri/capabilities fixes the error without touching Rust code.
  4. 4. Why does Tauri keep features in plugins instead of in the core?

    Opt-in plugins keep binaries small and reduce what an attacker could reach if the frontend were compromised.

Summary

  • Plugins add native features: a Rust crate, an npm package, permissions and optionally mobile code.
  • npm run tauri add <name> installs and wires a plugin; by hand you add the crate, call .plugin(...::init()) and grant permissions.
  • Calls travel as plugin:<name>|<command> and are checked against capabilities before Rust code runs.
  • Each plugin has a default permission set you can extend or restrict.
  • Add only the plugins you need, and guard desktop-only ones with cfg(desktop).

Next: Files and Dialogs