| Crates.io | tauri-plugin-prevent-default |
| lib.rs | tauri-plugin-prevent-default |
| version | 4.0.3 |
| created_at | 2024-07-01 03:44:36.450244+00 |
| updated_at | 2025-11-27 22:42:49.249443+00 |
| description | Disable default browser shortcuts |
| homepage | https://github.com/ferreira-tb/tauri-plugin-prevent-default |
| repository | https://github.com/ferreira-tb/tauri-plugin-prevent-default |
| max_upload_size | |
| id | 1288351 |
| size | 159,186 |
Disable default browser shortcuts in your Tauri app, e.g. F3 or Ctrl+J.
Install the plugin by adding the following to your Cargo.toml file:
[dependencies]
tauri-plugin-prevent-default = "4"
Register the plugin with Tauri:
src-tauri/src/main.rs
tauri::Builder::default()
.plugin(tauri_plugin_prevent_default::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
You can also use flags to determine which shortcuts the plugin should disable. By default, it will disable all of them.
use tauri_plugin_prevent_default::Flags;
let prevent = tauri_plugin_prevent_default::Builder::new()
.with_flags(Flags::CONTEXT_MENU | Flags::PRINT | Flags::DOWNLOADS)
.build();
tauri::Builder::default()
.plugin(prevent)
.run(tauri::generate_context!())
.expect("error while running tauri application");
If you want to keep only CONTEXT_MENU, DEV_TOOLS, and RELOAD enabled in dev mode, you can build the plugin with tauri_plugin_prevent_default::debug instead.
tauri::Builder::default()
.plugin(tauri_plugin_prevent_default::debug())
.run(tauri::generate_context!())
.expect("error while running tauri application");
[!TIP] For platform-specific options, see its corresponding section.
use tauri_plugin_prevent_default::Flags;
// This will disable all shortcuts, except `FIND` and `RELOAD`.
tauri_plugin_prevent_default::Builder::new()
.with_flags(Flags::all().difference(Flags::FIND | Flags::RELOAD))
.build()
use tauri_plugin_prevent_default::Flags;
tauri_plugin_prevent_default::Builder::new()
.with_flags(Flags::keyboard())
.build()
use tauri_plugin_prevent_default::KeyboardShortcut;
use tauri_plugin_prevent_default::ModifierKey::{CtrlKey, ShiftKey};
tauri_plugin_prevent_default::Builder::new()
.shortcut(KeyboardShortcut::new("F12"))
.shortcut(KeyboardShortcut::with_modifiers("E", &[CtrlKey, ShiftKey]))
.shortcut(KeyboardShortcut::with_shift_alt("I"))
.build();
fn main() {
tauri::Builder::default()
.plugin(prevent_default())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#[cfg(debug_assertions)]
fn prevent_default() -> tauri::plugin::TauriPlugin<tauri::Wry> {
use tauri_plugin_prevent_default::Flags;
tauri_plugin_prevent_default::Builder::new()
.with_flags(Flags::all().difference(Flags::DEV_TOOLS | Flags::RELOAD))
.build()
}
#[cfg(not(debug_assertions))]
fn prevent_default() -> tauri::plugin::TauriPlugin<tauri::Wry> {
tauri_plugin_prevent_default::init()
}
Please read our versioning policy before using any of these options.
The platform-windows feature must be enabled. Check the documentation for more details.
[dependencies]
tauri-plugin-prevent-default = { version = "4", features = ["platform-windows"] }
use tauri_plugin_prevent_default::PlatformOptions;
tauri_plugin_prevent_default::Builder::new()
.platform(PlatformOptions::new()
// Whether general form information should be saved and autofilled.
.general_autofill(true)
// Whether password information should be autosaved.
.password_autosave(false)
// Whether browser-specific accelerator keys are enabled.
.browser_accelerator_keys(false)
// Whether the default context menus are shown in the webview.
.default_context_menus(false)
// Whether the webview renders the default JavaScript dialog box.
.default_script_dialogs(false)
)
.build()
This plugin follows SemVer, but features marked as unstable are experimental and may introduce breaking changes between minor versions.
This plugin requires Tauri 2.0 or later.