Skip to main content
A system tray icon lets your application remain available in the operating system’s notification area while the application is alive, even when no visible window is open. You create tray icons through app.createTrayIcon(), which registers the native resource with the application.
Tray icons are supported on Windows, macOS, and Linux. The Android backend explicitly rejects tray creation, and the published FreeBSD target is a GUI stub.

Creating a tray icon

Call app.createTrayIcon(TrayIconOptions) through the application. A readiness check is not required; you can create the icon before or after starting the event pump.

TrayIconOptions

Pass a TrayIconOptions object to app.createTrayIcon().

Icon data formats

The icon.data field accepts raw pixels or encoded image bytes:
  • Raw RGBA bytes — supply width and optionally height alongside a Buffer. The byte length must equal width × height × 4; if height is omitted, the icon is treated as square. Each pixel is four bytes: R, G, B, A.
  • Encoded image bytes — supply a Buffer containing a PNG, JPEG, WebP, GIF, BMP, ICO, or TIFF file without width or height. The native backend decodes the image automatically.
Providing height without width is invalid.
On Linux, the tray backend may not show an icon unless a menu is set. The title may also be hidden by the panel or tray implementation even when it is configured.

Methods

Once you have a TrayIcon instance returned by app.createTrayIcon(), you can call these methods at any time before the icon is disposed.

tray.id

Read-only string identifier set at creation time (or auto-generated).

tray.setIcon(data, width?, height?)

Replace the tray icon image at runtime. Supply raw RGBA data with width and optionally height (a missing height means a square icon), or encoded image bytes without dimensions. Providing height without width is invalid.

tray.removeIcon()

Remove and hide the icon from the tray area. The TrayIcon instance remains valid; restore it by calling setIcon() with image data again.

tray.setMenu(menu?)

Set or replace the context menu. Pass undefined or null to remove it where the platform supports removal. On Linux, once a menu has been set, the native tray backend does not remove or replace it through this API, so configure the initial menu before creating the tray icon.

tray.setTooltip(tooltip?)

Update the hover tooltip text. Not supported on Linux.

tray.setTitle(title?)

Set or clear the text label shown next to the icon. macOS supports it, and Linux can display it when an icon is also present; Windows does not support it.

tray.setVisible(visible)

Show or hide the tray icon without removing it. Hidden icons retain their configuration and can be made visible again.

tray.setIconAsTemplate(value)

Mark the icon as a monochrome template image. When true, macOS renders the icon using the appropriate foreground colour for the current menu-bar appearance (dark or light). macOS only.

tray.setShowMenuOnLeftClick(value)

Control whether a left-click opens the context menu. Not supported on Linux.

tray.setShowMenuOnRightClick(value)

Control whether a right-click opens the context menu. Not supported on Linux.

tray.showMenu()

Programmatically open the tray context menu from your Node.js code on Windows and macOS. The Linux tray backend does not support this operation.

tray.rect()

Return the bounding rectangle of the tray icon on screen, or null if the platform does not expose it.

Tray events

TrayIcon is a Node.js EventEmitter. Register listeners with tray.on(event, handler).

Clicking a menu item in the tray’s context menu does not fire a tray event. Instead, it fires the custom-menu-click event on the app instance, exactly the same as window menu clicks. Use customMenuEvent.id to identify which item was selected.
See the Menu — Handling menu clicks section for full details.

Platform notes


Disposal

Call tray.dispose() to remove the icon from the system tray immediately. You can also use the ECMAScript explicit resource management syntax with Symbol.dispose.
Check whether an icon has already been disposed:
When app.exit() is called, the Application object removes all tray icons it owns, regardless of whether the TrayIcon wrapper object is still reachable in your code. You do not need to call tray.dispose() before app.exit().