Notifications on Windows 10


On the tutorial page for Desktop Environment Integration, it says:

On Windows 10, notifications "just work".

Then it shows this code snippet:

new Notification('Title', {
  body: 'Notification with icon',
  icon: 'file:///C:/Users/feriese/Desktop/icon.png'

I tried adding this to the end of the app ready function but I got this error:

A JavaScript error occurred in the main process
Uncaught Exception:
ReferenceError: Notification is not defined

Then I tried adding this:

const Notification = electron.Notification;

and I got this error:

Uncaught Exception:
TypeError: Notification is not a function

What do I need to do to get notifications to “just work” on Windows 10?


Move the code calling Notification into the renderer process. The main process does not have access to standard web APIs.


Hello @john thanks for your reply here because I’ve read through dozen websites until I realized what you’re saying here so simply.
There’s only one question that remains unanswered: I’m using electron as a wrapper client to load an external website so I can’t move the code into the renderer process.
Do I need to executeJavascript with my call ?


You could simply make a hidden BrowserWindow and use that to trigger Notifications in a renderer process. But a question you could ask yourself is why use electron (with the weight of chromium behind it) if you never use anything in the renderer process?


executeJavascript should work fine. Just bear in mind that you won’t be able to do any callbacks, etc if you want a notification that contains buttons.

If you do need buttons, etc, you may need to do as MarshallOfSound suggested and fire up a hidden BrowserWindow to handle notifications.