Warning: Currently this API only works on ChromeOS and Windows.
To use this API,
call the $ref:notifications.create method,
passing in the notification details
via the options parameter:
chrome.notifications.create(id, options, creationCallback);
The $ref:notifications.NotificationOptions must include a $ref:notifications.TemplateType, which defines available notification details and how those details are displayed.
All template types
(basic, image, and list)
must include a notification title and message,
as well as an iconUrl, which is a link to a small icon that
is displayed to the left of the notification message. The image
template type also includes an imageUrl, which is a link to
an image that is previewed within the notification.
Due to a strict Content Security Policy
in packaged apps, these URLs must point to a local resource or use a
data URL.
Here's an example of a basic template:
var opt = {
type: "basic",
title: "Primary Title",
message: "Primary message to display",
iconUrl: "url_to_small_icon"
}
The list template displays items
in a list format:
var opt = {
type: "list",
title: "Primary Title",
message: "Primary message to display",
iconUrl: "url_to_small_icon",
items: [{ title: "Item1", message: "This is item 1."},
{ title: "Item2", message: "This is item 2."},
{ title: "Item3", message: "This is item 3."}]
}
Let us know if you have ideas for new templates with varying layouts by filing a crbug!
All notifications can include event listeners and event handlers that respond to user actions. For example, you can write an event handler to respond to an $ref:notifications.onButtonClicked event.
Consider including event listeners and handlers within the event page, so that notifications can pop-up even when the app or extension isn't running.