Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including electron-native-notification with all npm packages installed. Try it out:

var electronNativeNotification = require("electron-native-notification")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

electron-native-notification v1.2.1

Notification API polyfill in electron main process.

electron-native-notification

GitHub release JavaScript Style Guide

Easily display native desktop applications from your Electron main process.

Because Notifications use the HTML 5 Notification API, this usually only works from renderer processes.

However, it's a polyfill from https://developer.mozilla.org/en-US/docs/Web/API/notification.

Usage

Reference https://developer.mozilla.org/en-US/docs/Web/API/notification.

main.js:

const
  { app } = require('electron'),
  Notification = require('electron-native-notification');

app.on('ready', () => {

  const opt = { body: 'See? Really easy to use!' };

  const notification = new Notification('I am a notification!', opt);

  notification.on('show', () => {
    console.log('I\'m coming~');
  });

  notification.onclick = () => {
    console.log('On no! You touch me. It\'s hurt!!');
  };

  notification.addEventListener('close', () => {
    console.log('I\'ll be back!!');
  });

  notification.addListener('error', (err) => {
    console.error(err);
  });

  console.log('What does the notification say? ' + notification.body);

  setTimeout(() => notification.close(), 2000);

});

Polyfill what?

Constructor

  • Notification(title, options)

Properties

  • body (Read-only)
  • data (Read-only)
  • dir (Read-only)
  • icon (Read-only)
  • lang (Read-only)
  • onclick
  • onerror
  • tag (Read-only)
  • timestamp (Read-only)
  • title (Read-only)

Methods

  • close()
  • on() (Event register for node)
  • addListener() (Event register for node)
  • addEventListener() (Event register for javascript)

Events

  • error
  • click
  • close
  • show

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free