chrome.notifications
- Description
Use the
chrome.notifications
API to create rich notifications using templates and show these notifications to users in the system tray. - Permissions
notifications
Summary
- Types
- Methods
chrome.notifications.clear(notificationId: string, callback: function)
chrome.notifications.create(notificationId?: string, options: NotificationOptions, callback: function)
chrome.notifications.getAll(callback: function)
chrome.notifications.getPermissionLevel(callback: function)
chrome.notifications.update(notificationId: string, options: NotificationOptions, callback: function)
- Events
Types
NotificationButton
Properties
- iconUrlstring optional
Deprecated. Button icons not visible for Mac OS X users.
- titlestring
NotificationItem
Properties
- messagestring
Additional details about this item.
- titlestring
Title of one item of a list notification.
NotificationOptions
Properties
- appIconMaskUrlstring optional
Deprecated. The app icon mask is not visible for Mac OS X users.
A URL to the app icon mask. URLs have the same restrictions as iconUrl.
The app icon mask should be in alpha channel, as only the alpha channel of the image will be considered.
- buttonsNotificationButton[] optional
Text and icons for up to two notification action buttons.
- contextMessagestring optional
Alternate notification content with a lower-weight font.
- eventTimenumber optional
A timestamp associated with the notification, in milliseconds past the epoch (e.g.
Date.now() + n
). - iconUrlstring optional
A URL to the sender's avatar, app icon, or a thumbnail for image notifications.
URLs can be a data URL, a blob URL, or a URL relative to a resource within this extension's .crx file Required for
create
method. - imageUrlstring optional
Deprecated. The image is not visible for Mac OS X users.
A URL to the image thumbnail for image-type notifications. URLs have the same restrictions as iconUrl.
- isClickableboolean optional
Deprecated. This UI hint is ignored as of Chrome 67
- itemsNotificationItem[] optional
Items for multi-item notifications. Users on Mac OS X only see the first item.
- messagestring optional
Main notification content. Required for
create
method. - prioritynumber optional
Priority ranges from -2 to 2. -2 is lowest priority. 2 is highest. Zero is default. On platforms that don't support a notification center (Windows, Linux & Mac), -2 and -1 result in an error as notifications with those priorities will not be shown at all.
- progressnumber optional
Current progress ranges from 0 to 100.
- requireInteractionboolean optional
Indicates that the notification should remain visible on screen until the user activates or dismisses the notification. This defaults to false.
- silentboolean optional
Indicates that no sounds or vibrations should be made when the notification is being shown. This defaults to false.
- titlestring optional
Title of the notification (e.g. sender name for email). Required for
create
method. - typeTemplateType optional
Which type of notification to display. Required for
create
method.
PermissionLevel
Enum
"granted"
, or "denied"
TemplateType
Enum
"basic"
, "image"
, "list"
, or "progress"
Methods
clear
chrome.notifications.clear(notificationId: string, callback: function)
Clears the specified notification.
Parameters
- notificationIdstring
The id of the notification to be cleared. This is returned by
create
method. - callbackfunction
Called to indicate whether a matching notification existed.
The callback is required before Chrome 42.
The callback parameter should be a function that looks like this:
(wasCleared: boolean) => {...}
- wasClearedboolean
create
chrome.notifications.create(notificationId?: string, options: NotificationOptions, callback: function)
Creates and displays a notification.
Parameters
- notificationIdstring optional
Identifier of the notification. If not set or empty, an ID will automatically be generated. If it matches an existing notification, this method first clears that notification before proceeding with the create operation. The identifier may not be longer than 500 characters.
The
notificationId
parameter is required before Chrome 42. - options
Contents of the notification.
- callbackfunction
Returns the notification id (either supplied or generated) that represents the created notification.
The callback is required before Chrome 42.
The callback parameter should be a function that looks like this:
(notificationId: string) => {...}
- notificationIdstring
getAll
chrome.notifications.getAll(callback: function)
Retrieves all the notifications of this app or extension.
Parameters
- callbackfunction
Returns the set of notification_ids currently in the system.
The callback parameter should be a function that looks like this:
(notifications: object) => {...}
- notificationsobject
getPermissionLevel
chrome.notifications.getPermissionLevel(callback: function)
Retrieves whether the user has enabled notifications from this app or extension.
Parameters
- callbackfunction
Returns the current permission level.
The callback parameter should be a function that looks like this:
(level: PermissionLevel) => {...}
- level
update
chrome.notifications.update(notificationId: string, options: NotificationOptions, callback: function)
Updates an existing notification.
Parameters
- notificationIdstring
The id of the notification to be updated. This is returned by
create
method. - options
Contents of the notification to update to.
- callbackfunction
Called to indicate whether a matching notification existed.
The callback is required before Chrome 42.
The callback parameter should be a function that looks like this:
(wasUpdated: boolean) => {...}
- wasUpdatedboolean
Events
onButtonClicked
chrome.notifications.onButtonClicked.addListener(listener: function)
The user pressed a button in the notification.
Event
- listenerfunction
The listener parameter should be a function that looks like this:
(notificationId: string, buttonIndex: number) => {...}
- notificationIdstring
- buttonIndexnumber
onClicked
chrome.notifications.onClicked.addListener(listener: function)
The user clicked in a non-button area of the notification.
Event
- listenerfunction
The listener parameter should be a function that looks like this:
(notificationId: string) => {...}
- notificationIdstring
onClosed
chrome.notifications.onClosed.addListener(listener: function)
The notification closed, either by the system or by user action.
Event
- listenerfunction
The listener parameter should be a function that looks like this:
(notificationId: string, byUser: boolean) => {...}
- notificationIdstring
- byUserboolean
onPermissionLevelChanged
chrome.notifications.onPermissionLevelChanged.addListener(listener: function)
The user changes the permission level. As of Chrome 47, only ChromeOS has UI that dispatches this event.
Event
- listenerfunction
The listener parameter should be a function that looks like this:
(level: PermissionLevel) => {...}
- level
onShowSettings
chrome.notifications.onShowSettings.addListener(listener: function)
The user clicked on a link for the app's notification settings. As of Chrome 47, only ChromeOS has UI that dispatches this event. As of Chrome 65, that UI has been removed from ChromeOS, too.
Event
- listenerfunction
Deprecated. Custom notification settings button is no longer supported.
The listener parameter should be a function that looks like this:
() => {...}