Skip to content

Latest commit

 

History

History
148 lines (97 loc) · 3.75 KB

File metadata and controls

148 lines (97 loc) · 3.75 KB

notifications

Documentation: Chrome Notifications API

A promise-based wrapper for the Chrome notifications API to create and manage desktop notifications.

Methods

Events


clearNotification

clearNotification(notificationId: string): Promise<boolean>

Clears the notification with the specified ID, resolving to true if the notification existed and was cleared.

createNotification

createNotification(
  options: chrome.notifications.NotificationOptions,
  notificationId?: string
): Promise<string>

Creates a notification with the given options and optional ID, returning the notification ID.

getAllNotifications

getAllNotifications(): Promise<object>

Retrieves all currently displayed notifications. The returned object maps notification IDs to true values, as provided by chrome.notifications.getAll.

getNotificationPermissionLevel

getNotificationPermissionLevel(): Promise<string>

Gets the current permission level for notifications (e.g., "granted" or "denied").

updateNotification

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

isAvailableNotifications(): boolean

Returns true if the chrome.notifications API is available in the current environment, otherwise false.

clearAllNotifications

clearAllNotifications(): Promise<void>

Clears all currently displayed notifications.

onNotificationsButtonClicked

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

onNotificationsClicked(
  callback: (notificationId: string) => void
): () => void

Adds a listener for when a notification itself is clicked. Returns an unsubscribe function.

onNotificationsClosed

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

onNotificationsPermissionLevelChanged(
  callback: (level: chrome.notifications.PermissionLevel) => void
): () => void

Adds a listener for changes to the notifications permission level. Returns an unsubscribe function.