Skip to content

Context Menu

Call ContextMenu.showContextMenu() from the main process. The menu opens at the current global pointer position.

import { ContextMenu } from "electrobun/main";
ContextMenu.showContextMenu([
{
label: "Open",
action: "open",
accelerator: "o",
data: { source: "context-menu" },
},
{
label: "More",
submenu: [
{ label: "Rename", action: "rename" },
{ label: "Delete", action: "delete", enabled: false },
],
},
{ type: "separator" },
{ role: "copy" },
{ role: "paste" },
]);
ContextMenu.on("context-menu-clicked", (event: unknown) => {
console.log("Context menu action", event);
});

Normal items support label, action or role, data, submenu, enabled, checked, hidden, tooltip, and accelerator. Separators accept either separator or divider as their type.

In a webview, prevent the browser’s default contextmenu event and make an RPC request to the main process, which owns the native menu API.

Context menus are currently implemented on macOS and Windows. Linux support is not yet available.