Documentation: Chrome Notifications API
A promise-based wrapper for the Chrome notifications API to create and manage desktop notifications.
- clearNotification(notificationId)
- createNotification(options, notificationId?)
- getAllNotifications()
- getNotificationPermissionLevel()
- updateNotification(options, notificationId)
- isAvailableNotifications()
- clearAllNotifications()
- onNotificationsButtonClicked(callback)
- onNotificationsClicked(callback)
- onNotificationsClosed(callback)
- onNotificationsPermissionLevelChanged(callback)
clearNotification(notificationId: string): Promise<boolean>
Clears the notification with the specified ID, resolving to true if the notification existed and was cleared.
createNotification(
options: chrome.notifications.NotificationOptions,
notificationId?: string
): Promise<string>
Creates a notification with the given options and optional ID, returning the notification ID.
getAllNotifications(): Promise<object>
Retrieves all currently displayed notifications. The returned object maps notification IDs to true values, as provided by chrome.notifications.getAll.
getNotificationPermissionLevel(): Promise<string>
Gets the current permission level for notifications (e.g., "granted" or "denied").
updateNotification(
options: chrome.notifications.NotificationOptions,
notificationId: string
): Promise<boolean>
Updates an existing notification with new options, resolving to true if the notification was updated.
isAvailableNotifications(): boolean
Returns true if the chrome.notifications API is available in the current environment, otherwise false.
clearAllNotifications(): Promise<void>
Clears all currently displayed notifications.
onNotificationsButtonClicked(
callback: (notificationId: string, buttonIndex: number) => void
): () => void
Adds a listener for when a button on a notification is clicked. Returns an unsubscribe function.
onNotificationsClicked(
callback: (notificationId: string) => void
): () => void
Adds a listener for when a notification itself is clicked. Returns an unsubscribe function.
onNotificationsClosed(
callback: (notificationId: string, byUser: boolean) => void
): () => void
Adds a listener for when a notification is closed, including whether it was closed by the user. Returns an unsubscribe function.
onNotificationsPermissionLevelChanged(
callback: (level: chrome.notifications.PermissionLevel) => void
): () => void
Adds a listener for changes to the notifications permission level. Returns an unsubscribe function.