Skip to main content

Write Tauri Plugins

Plugins allow you to hook into the Tauri application lifecycle and introduce new commands.

Writing a Plugin

To write a plugin you just need to implement the tauri::plugin::Plugin trait:

use tauri::{plugin::{Plugin, Result as PluginResult}, Runtime, PageLoadPayload, Window, Invoke, AppHandle};

struct MyAwesomePlugin<R: Runtime> {
invoke_handler: Box<dyn Fn(Invoke<R>) + Send + Sync>,
// plugin state, configuration fields

// the plugin custom command handlers if you choose to extend the API.
// this will be accessible with `invoke('plugin:awesome|initialize')`.
// where `awesome` is the plugin name.
fn initialize() {}

// this will be accessible with `invoke('plugin:awesome|do_something')`.
fn do_something() {}

impl<R: Runtime> MyAwesomePlugin<R> {
// you can add configuration fields here,
// see
pub fn new() -> Self {
Self {
invoke_handler: Box::new(tauri::generate_handler![initialize, do_something]),

impl<R: Runtime> Plugin<R> for MyAwesomePlugin<R> {
/// The plugin name. Must be defined and used on the `invoke` calls.
fn name(&self) -> &'static str {

/// The JS script to evaluate on initialization.
/// Useful when your plugin is accessible through `window`
/// or needs to perform a JS task on app initialization
/// e.g. "window.awesomePlugin = { ... the plugin interface }"
fn initialization_script(&self) -> Option<String> {

/// initialize plugin with the config provided on `tauri.conf.json > plugins > $yourPluginName` or the default value.
fn initialize(&mut self, app: &AppHandle<R>, config: serde_json::Value) -> PluginResult<()> {

/// Callback invoked when the Window is created.
fn created(&mut self, window: Window<R>) {}

/// Callback invoked when the webview performs a navigation.
fn on_page_load(&mut self, window: Window<R>, payload: PageLoadPayload) {}

/// Extend the invoke handler.
fn extend_api(&mut self, message: Invoke<R>) {

Note that each function on the Plugin trait is optional, except the name function.

Using a plugin

To use a plugin, just pass an instance of the MyAwesomePlugin struct to the App's plugin method:

fn main() {
let awesome_plugin = MyAwesomePlugin::new();
.expect("failed to run app");

Official Tauri Plugins