npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

browser-notifications-api

v1.1.4

Published

A lightweight wrapper for the native Browser Notifications API. Simplifies permission requests and notification display with a consistent, cross-browser interface. Perfect for PWAs, Alerts and User Engagement features.

Readme

Browser Notifications API package

npm version NPM License GitHub code size in bytes

A lightweight wrapper for the native Browser Notifications API. Simplifies permission requests and notification display with a consistent, cross-browser interface. Perfect for PWAs, Alerts and User Engagement features.


Installation

npm i browser-notifications-api

Usage

Basic Example

import BrowserNotificationsAPI from 'browser-notifications-api';

const notificationsAPI = new BrowserNotificationsAPI({
    // global configuration object
    // default value(s) will be used for any missed option
});

// Manual Request for Permissions
let notificationPermission = await notificationsAPI.askForPermission();

// Built-in button for Request Notification, return HTMLElement
let btnEl = notificationsAPI.permissionRequestButton({
    //btn options
});

// Display Notification, return Notification instance
const customNotifcation = notificationsAPI.showNotification({
    // single notification config
    // check notificationOptions as reference
});

const allNotificationsSent = notificationsAPI.getAllNotifications();
//return object with all notifications with format: 'tag' -> [Notification, ... ]
// { 
//   N_1757860285783: [Notification],
//   N_1757860291945: [Notification],
//   test:[Notification, Notification, Notification]
// }

const notificationsByTag = notificationsAPI.getNotificationByTag('tag');
// return all notifications (array) related to tag, 'null' in case of empty result.

Configuration

// Default Configuration
const configuration = {
    permissions: {
        // permission request strategy
        askOn: 'init', // -> init, on_first_notification, manual
        askOneTime: true, // ask permissions only one time
        disableOnActiveWindow: true, // do not show notification once window is active
        onGranted: null, // function, executed once permission is granted
        onDenied: null // function, executed once permission is denied
    },
    notificationOptions: {
        title: '', // notification title
        body: '', // notification content
        badge: null, // URL of an image to represent the notification when there is not enough space to display the notification itself
        data: null, // object/array/string, can be used inside notification actions (click/close/etc)
        dir: 'auto', // text direction -> 'ltr', 'rtl'.
        icon: null, // URL of an icon to be displayed as part of the notification
        image: null, // URL of an image to be displayed as part of the notification
        requireInteraction: false, // boolean value indicating that a notification should remain active until the user clicks or dismisses it, rather than closing automatically
        silent: null, // https://developer.mozilla.org/en-US/docs/Web/API/Notification/silent
        tag: '', // string, identifying tag for the notification, if empty 'N_timestamp' will be used by default
        onShow: null, // function, executed once notification is displayed
        onClick: null, // function, executed once user clicked on notification 
        onClose: null, // function, executed once user closed notification
        onError: null // function, executed on error
    }
};

// Default Built-In button configuration
const builtInButtonOptions = {
    text: 'Enable Notifications', // Button text
    id: null, // Button ID
    classList: [], //list of classes
    attributes: { // list of attributes
        type: 'button'
    },
    appendTo: null, // ID or HTMLElement
    removeOnGranted: true, // remove button from DOM once permission is granted
    onClick: null, //custom onClick, triggers after permission request.
};

Availability / Browser Compatibility

Browser Compatibility -> MDN

[!IMPORTANT] Secure Context is required, ref: MDN

Notification support is required


Author

Alexey Khamitsevich


Licence

MIT