Example
First, declare the notifications permission in your manifest:
{ "name": "My extension", "manifest_version": 2, ... "permissions": [ "notifications" ], ... // Note: Because of bug 134315, you must declare any images you // want to use with createNotification() as a web accessible resource. "web_accessible_resources": [ "48.png" ], }
Then, use webkitNotifications object to create notifications:
// Note: There's no need to call webkitNotifications.checkPermission(). // Extensions that declare the notifications permission are always // allowed create notifications. // Create a simple text notification: var notification = webkitNotifications.createNotification( '48.png', // icon url - can be relative 'Hello!', // notification title 'Lorem ipsum...' // notification body text ); // Or create an HTML notification: var notification = webkitNotifications.createHTMLNotification( 'notification.html' // html url - can be relative ); // Then show the notification. notification.show();
Communicating with Other Views
You can communicate between a notification and other views in your extension usingextension.getBackgroundPage and extension.getViews. For example:
// Inside a notification... chrome.extension.getBackgroundPage().doThing(); // From the background page... chrome.extension.getViews({type:"notification"}).forEach(function(win) { win.doOtherThing(); });