chrome-notifications
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

chrome-notifications

npm version build License

ko-fi

Overview

Helper for chrome.notifications API.

Notes

Installation

You can install this library using npm:

npm install chrome-notifications

Methods

create

Creates and displays a notification.

import { Notifications } from "chrome-notifications";

const options = {
  type: "basic",
  title: "My Notification",
  message: "This is a sample notification",
  iconUrl: "icon.png",
};

Notifications.create(options, "my-notification-id", (notification) => {
  console.log(notification);
});

// Output:
//   Object{
//     notificationId: "38fde96f-43b1-4736-969e-2da10417c024",
//     type: "basic",
//     title: "My Notification",
//     message: "This is a sample notification",
//     iconUrl: "icon.png"
//   }

update

Updates an existing notification.

import { Notifications } from "chrome-notifications";

const notificationId = "38fde96f-43b1-4736-969e-2da10417c024";
const newOptions = {
  title: "Updated Notification",
  message: "This is an updated notification",
};

Notifications.update(notificationId, newOptions, (notification) => {
  console.log(notification);
});

// Output:
//   Object{
//     notificationId: "38fde96f-43b1-4736-969e-2da10417c024",
//     type: "basic",
//     title: "Updated Notification",
//     message: "This is an updated notification",
//     iconUrl: "icon.png"
//   }

clear

Clears the specified notification.

import { Notifications } from "chrome-notifications";

const notificationId = "38fde96f-43b1-4736-969e-2da10417c024";

Notifications.clear(notificationId, (wasCleared) => {
  console.log(wasCleared);
});

// Output: true

getAll

Retrieves all the notifications of this app or extension.

import { Notifications } from "chrome-notifications";

Notifications.getAll().then((notifications) => {
  console.log(notifications);
});

// Output:
//   Array [
//     Object {
//       notificationId: "131aa054-c1b3-485b-a200-83bdcba8421c",
//       active: true
//     }
//   ]

getPermissionLevel

Retrieves whether the user has enabled notifications from this app or extension.

import { Notifications } from "chrome-notifications";

Notifications.getPermissionLevel().then((permissionLevel) => {
  console.log(permissionLevel);
});

// Output:
//   Object{
//     level: "granted",
//     isGranted: true,
//     isDenied: false
//   }

Link

License

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i chrome-notifications

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

16 kB

Total Files

13

Last publish

Collaborators

  • hidaka