Skip to content

Instantly share code, notes, and snippets.

@CodeLeom
Created June 10, 2025 13:03
Show Gist options
  • Select an option

  • Save CodeLeom/2ff9797ee6f89fd38f70f521dfa465e3 to your computer and use it in GitHub Desktop.

Select an option

Save CodeLeom/2ff9797ee6f89fd38f70f521dfa465e3 to your computer and use it in GitHub Desktop.
how to enable push notification on electron

Integrate Push notification via Firebase Cloud Messaging (FCM) or WebSocket

Firebase Cloud Messaging (FCM)

Use electron-push-receiver

npm install electron-push-receiver
const PushReceiver = require('electron-push-receiver');

app.whenReady().then(() => {
  createWindow();

  PushReceiver.setup(webContents, null, true);

  webContents.on('push-receiver-message', (event, message) => {
    new Notification({ title: message.notification.title, body: message.notification.body }).show();
    app.dock.setBadge('1'); // Update badge
  });
});

:info:

You must include your FCM credentials.json from Firebase.

Using WebSockets

If you control your backend, use WebSockets:

Use ws client inside Electron:

const WebSocket = require('ws');
const socket = new WebSocket('wss://your-server.com');

socket.onmessage = (msg) => {
  const data = JSON.parse(msg.data);
  new Notification({ title: 'New Message', body: data.text }).show();
  app.dock.setBadge('1'); // Or increment
};

Works offline and cross-platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment