Electron Setup

Send push notifications to your Electron app with Pushy.

Create an App

The first step involves signing up and creating your first app on Pushy.

If you have already created your app on Pushy for another platform, simply configure your existing app with your Web Push Hostname (enter your domain) in the App Settings tab and proceed to the next step.

Note: You can upgrade to our Pro plan at any time by setting up a payment method in the Billing page.

Click Create and proceed to the next step.

Install the SDK

Run the following command in the root directory of your project to install the pushy-electron package from npm:

npm install pushy-electron --save
Modify Content Security Policy

Please place the following <meta> declaration in your index.html:

<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
Enable Node Integration

Please ensure {nodeIntegration: true} is configured for your BrowserWindow in your ipcMain file as follows:

// Create the browser window
mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
        nodeIntegration: true
Modify Electron App

Require the package in one of your ipcRenderer (browser-context) files like so:

const Pushy = require('pushy-electron');

Invoke Pushy.listen() so that Pushy's internal notification service will start itself:

// Start the Pushy service
Register Devices

Devices need to be uniquely identified to receive push notifications.

Every device is assigned a unique token that you can use to push it at any given time. Once the device has been assigned a token, it should be stored in your application's backend database. When you're ready to push the device, your backend server will send its token to our REST API, and we'll deliver the push notification to the corresponding device.

Add the following code to register the device for push notifications, making sure to populate the appId variable with your Pushy App ID (Pushy Dashboard -> Click your app -> App Settings -> App ID):

// Register device for push notifications
Pushy.register({ appId: 'your-app-id' }).then(function (deviceToken) {
    // Print device token to console
    console.log('Pushy device token: ' + deviceToken);
}).catch(function (err) {
    // Handle registration errors
    alert('Pushy Error: ' + err.message);

Note: You may also await this method from an async function.

Listen for Notifications

Call the Pushy.setNotificationListener((data) => {}) method from your app to listen for incoming push notifications:

// Listen for push notifications
Pushy.setNotificationListener((data) => {
    // Print notification payload data
    console.log('Received notification: ' + JSON.stringify(data));

    // Display an alert with the "message" payload value
    alert('Received notification: ' + data.message);

Feel free to modify this sample code to suit your own needs.

Note: You may currently only register one notification listener at a time for your app.

Parse Notification Data

Any payload data that you send with your push notifications is made available to your app via the data parameter of your notification listener.

If you were to send a push notification with the following data:

{"id": 1, "success": true, "message": "Hello World"}

Then you'd be able to retrieve each value from within your notification listener callback like so:

let id =; // number
let success = data.success; // bool
let message = data.message; // string

Note: Unlike GCM / FCM, we do not stringify your payload data, except if you supply JSON objects or arrays.

Subscribe to Topics (Optional)

Optionally subscribe the device to one or more topics to target multiple users with a shared interest when sending notifications.

Depending on your app's notification criteria, you may be able to leverage topics to simply the process of sending the same notification to multiple users. If your app only sends personalized notifications, skip this step and simply target individual devices by specifying their tokens.

Add the following code to your app to subscribe a registered device to a topic:

// Make sure the device is registered
if (Pushy.isRegistered()) {
    // Subscribe the device to a topic
    Pushy.subscribe('news').then(() => {
        // Subscribe successful
        alert('Subscribed to topic successfully');
    }).catch((err) => {
        // Handle errors

Note: Replace news with your own case-sensitive topic name that matches the following regular expression: [a-zA-Z0-9-_.]+.

You can then notify multiple devices subscribed to a certain topic by specifying the topic name (prefixed with /topics/) as the to parameter in the Send Notifications API.

Send Test Notification

Input your device token and select your app to send a test push notification:

Note: You can specify a topic instead of a device token (i.e. /topics/news). Also, if your app is not automatically detected, please manually copy the Secret API Key from the Dashboard and paste it into the form.

Check if your device received the notification. Did it work? If not, contact us, we'll be glad to help.

Integration Complete

Congratulations on implementing Pushy in your app!

Now, all that's left is to setup your backend. Head on over to the Backend Setup guide to begin persisting device tokens as well as implementing the logic for sending push notifications to your users.