Library / SDK
sindresorhus/electron-context-menu avatar
sindresorhus/electron-context-menu

electron-context-menu: the right-click menu Electron leaves out

Context menu for your Electron app

1,477 stars166 forksJavaScriptMIT

At a glance

What is it?
electron-context-menu gives an Electron application a working context menu with spellchecking, cut, copy and paste, image and video saving, and an Inspect Element item in development, all configurable through a large set of boolean options. It suits a developer who has hit the blank right-click in a packaged Electron app, and it only runs in the main process.
Who is it for?
Adopt electron-context-menu if your Electron app has no right-click menu and you would rather not write the menu plumbing yourself, since the defaults cover most of what a user expects. Skip it if you need a custom menu that is not right-click shaped, since the module only handles the context menu event.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 33 days ago.
What is it written in?
Mainly JavaScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.

Editorial analysis

The gap in Electron, and what the module fills

Electron does not have a built-in context menu, and the README is blunt about the consequence, that you are supposed to handle that yourself, but it is both tedious and hard to get right. The module gives you a nice extensible context menu with spellchecking and items like Cut, Copy and Paste for text, Save Image for images, and Copy Link for links, and it adds an Inspect Element menu item when in development so you can quickly view items in the inspector like in Chrome. That last one matters more than it sounds. In a packaged Electron application, the usual way to open the devtools is a menu item or a keyboard shortcut, and without any context menu at all the right-click does nothing, which is exactly the state most Electron apps ship in. The primary language is JavaScript, the licence is MIT, the last push was on 2026-09-20, and the releases are v5.1.0 on 2026-09-20, v5.0.0 on 2026-09-01 and v4.1.2 on 2026-03-19.

Installing and calling it

The install is one command:

sh
npm install electron-context-menu

and it requires Electron 44 or later. The usage is a single call in the main process, with the simplest form attaching the menu to every window:

js
import {app, BrowserWindow} from 'electron';
import contextMenu from 'electron-context-menu';

contextMenu({
	showSaveImageAs: true
});

The call returns a function that disposes of the created event listeners, which is the part worth knowing about in a long-lived main process where you might want to tear the menu down. The package manifest shows why the call has to happen in the main process, since it depends on `electron-is-dev` to decide whether to add the Inspect Element item, and on `electron-dl` to handle the download when you save an image or a video. It also depends on `cli-truncate`, which is what keeps a long file path in a menu label from breaking the layout. The `files` array in the manifest lists only `index.js` and `index.d.ts`, so the module ships as two files.

Extending the menu with prepend and append

The extension model is the part that makes it more than a canned menu, and the two hooks are symmetric. `prepend` should return an array of MenuItem to be prepended to the context menu, and `append` the same for the end. Both receive four arguments, the array of default actions that can be used, the parameters object from Electron's context-menu event, the window or view the menu was requested for, and the context menu event itself. The example shows the pattern, with a Rainbow item visible only when right-clicking images and a Search Google for the selection item visible only when there is selected text, opened through `shell.openExternal`. The rule about overriding a default is precise and slightly surprising. A menu item with an `id` matching one of the default action names, for example `copy`, replaces that default action and stays where `prepend` or `append` put it, and the default is replaced even when the custom item is not visible. So an item you hide still suppresses the built-in one.

The options, and the platform-dependent defaults

The option list is long and mostly booleans, and the defaults are worth reading closely because several of them are conditional. `showLearnSpelling` defaults to true and shows the Learn Spelling item when right-clicking text, though the spellcheck only appears when right-clicking a misspelled word. `showLookUpSelection` and `showSearchWithGoogle` also default to true, and `showDictionarySuggestions` is on by default. `showSelectAll` is the interesting one, defaulting to false on macOS and true on Windows and Linux, which reflects the platform convention rather than a bug. The image and video items are all off by default except `showCopyImage`, which is on. `showCopyImageAddress` and `showCopyVideoAddress` are hidden for `file://` URLs by default, a detail that matters for an app loading local content, and the reference to `showFileUrlItems` is where you would change that. There is also `showSaveImageAs` for the Save Image As item, and a `<canvas>` cannot be saved since it has no URL to download.

The custom search option, and replacing the built-in one

The `search` option lets you add your own search menu item when right-clicking text, and it works by turning off the built-in one with `showSearchWithGoogle: false` and adding your own entry, either directly or through the default actions with `defaultActions.search()`. The `url` must contain `%s`, which is replaced by the search query, in the same way Chrome does it, and the label may contain the `{selection}` placeholder which is replaced by the currently selected text. The documented example is a DuckDuckGo search:

js
{
	search: {
		label: 'Search with DuckDuckGo',
		url: 'https://duckduckgo.com/?q=%s'
	},
	showSearchWithGoogle: false
}

The `{selection}` placeholder also works in any MenuItem label you add through prepend or append, which is what makes a custom item useful rather than decorative, since a menu entry that can act on what the user has selected is worth having and one that cannot is noise.

Scoping the menu, and the video items

The `window` option takes a BrowserWindow, BrowserView, WebContents or WebContentsView and attaches the menu to that one, and when it is not specified the menu is added to all existing and new windows. To attach it to a `<webview>` you pass its WebContents, which you can get in the main process with `webContents.fromId(...)` using the id from `webview.getWebContentsId()`. That is the detail that makes the module usable in an application with webviews, where a global menu would appear over content you did not intend it for. The video items are the newest group, with `showCopyVideoAddress`, `showSaveVideo`, `showSaveVideoAs`, `showCopyVideoFrame` and `showSaveVideoFrameAs`, all off by default, and `showCopyVideoFrame` copies the video frame at the click position to the clipboard. The frame-related items depend on the media having a position, which is why they are described in terms of the click position rather than a general frame.

Editorial conclusion

Adopt electron-context-menu if your Electron app has no right-click menu and you would rather not write the menu plumbing yourself, since the defaults cover most of what a user expects. Skip it if you need a custom menu that is not right-click shaped, since the module only handles the context menu event. Before you install, note that it can only be used in the main process, that it requires Electron 44 or later, and that the package itself needs Node 24 or newer.

Frequently asked questions

What does electron-context-menu do?

It adds a context menu to an Electron app, with spellchecking, Cut, Copy and Paste for text, Save Image for images, Copy Link for links, and an Inspect Element item in development. Electron itself has no built-in context menu.

Where can electron-context-menu be used?

Only in the main process. The package reads the development state to decide whether to add the Inspect Element item, and uses the download helper to save images and video.

How do I add my own items to the Electron context menu?

Use the prepend or append options, each of which receives the default actions array, the context-menu parameters, the window it was requested for and the event. A MenuItem with an id matching a default action name such as copy replaces that default and stays where you put it, even when your item is hidden.

How do I change the search engine in the Electron context menu?

Set showSearchWithGoogle to false and supply a search option with a label and a url containing %s, which is replaced by the query, for example a DuckDuckGo url of 'https://duckduckgo.com/?q=%s'. Labels can use the {selection} placeholder.

Official sources

  1. Issues
  2. License: MIT
  3. README
  4. Releases
  5. sindresorhus/electron-context-menu on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/sindresorhus-electron-context-menu.svg)](https://hysenlabs.com/projects/sindresorhus-electron-context-menu)

Was this useful?