Skip to main content
A system tray icon lets your application live persistently in the operating system’s notification area (system tray) even when no visible window is open. You create tray icons through app.createTrayIcon() — this ensures creation happens on the event-loop thread, which is required for native UI objects on all three platforms.

Creating a tray icon

Call app.createTrayIcon(TrayIconOptions) inside (or after) app.whenReady() to guarantee the event loop is running before the native tray icon is registered.

TrayIconOptions

Pass a TrayIconOptions object to app.createTrayIcon().

Icon data formats

The icon.data field accepts two formats:
  • Raw RGBA bytes — supply width and height alongside a Buffer whose length equals width × height × 4. 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.

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 height, or encoded image bytes without dimensions.

tray.removeIcon()

Remove and hide the icon from the tray area. The TrayIcon instance remains valid and you can restore it by calling setIcon().

tray.setMenu(menu?)

Replace the context menu. Pass undefined or call without arguments to remove the menu entirely.

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 only. On other platforms this call is a no-op.

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, without waiting for a user click.

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().