chromium-notification-retriever v1.2.3
Chromium Notification Retriever
A TypeScript library for retrieving notifications saved by Chromium-based browsers.
Installation
npm install chromium-notification-retriever
Usage
const { Retriever } = require("chromium-notification-retriever");
// Specify the path to the LevelDB database where your browser stores notification information
// E.g. "C:/Users/<username>/AppData/Local/Microsoft/Edge/User Data/Default/Platform Notifications"
// for a default Edge installation on Windows
const dbPath = "/path/to/your/chromium/db";
// Optional: Provide configuration options
const options = {
refreshOnRetrieve: true, // Whether to refresh the database on each retrieval (default: true)
watchInterval: 1000, // Time between each check for new notifications (default: 3000)
};
// Create a new Retriever instance
const retriever = new Retriever(dbPath, options);
// Retrieve notifications
retriever.retrieve({ limit: 10 }).then((notifications) => {
notifications.forEach((notification) => {
// Access notifications
console.log(notification);
});
});
// Watch for new notifications
retriever.watch((notification) => {
// This callback will be called whenever a new notification is found
console.log(notification);
});
// Retrieve a specific notification by its key
const key = "notification_key";
const notification = await retriever.get(key);
if (notification) console.log(notification);
else console.log("Notification not found.");
API Reference
Retriever
constructor(dbPath: string, options?: RetrieverOptions): Retriever
Creates a new Retriever
instance.
dbPath
: Path to the LevelDB database where the browser stores notification information.options
(optional): Configuration options.
refresh(): void
Makes a new copy of the notification database with up-to-date notifications.
Unnecessary if refreshOnRetrieve
is enabled.
retrieve(limit?: number, refresh?: boolean): Promise<NotificationInfo[]>
Retrieves notifications from the database. .
limit
(optional): Maximum number of notifications to retrieve.refresh
(optional): OverridesrefreshOnRetrieve
.
get(key: string, refresh?: boolean): Promise<NotificationInfo | undefined>
Retrieves a specific notification by its key. If passed, refresh
overrides refreshOnRetrieve
.
key
: The key of the notification.refresh
(optional): OverridesrefreshOnRetrieve
.
Returns a notification if one exists with that key, or undefined
otherwise.
watch(listener: (notification: NotificationInfo) => void): () => void
Calls listener
for every new notification found.
listener
: Function to be called whenever a new notification is found.
Returns a function that removes the listener
.
destroy(): void
Closes and deletes the copy of the notification database.
Note that old copies of databases are always deleted when you import Retriever
, so calling this might not be necessary.
License
This project is licensed under the MIT License.