I have built the following code with the Firefox add-on SDK that successfully adds a notification to the NotificationBox on the current active tab, at page-load time.
How can I change it to use the parameterised version of the getNotificationBox() method, in order to select the NotificationBox on the tab that belongs to the Document being loaded?
const observer = require( 'observer-service' );
var {Cc, Ci, Cr, Cu} = require( 'chrome' );
observer.add( 'document-element-inserted', function( document ) {
var window = document.defaultView;
var mainWindow = window.QueryInterface( Ci.nsIInterfaceRequestor )
.getInterface( Ci.nsIWebNavigation )
.QueryInterface( Ci.nsIDocShellTreeItem )
.rootTreeItem
.QueryInterface( Ci.nsIInterfaceRequestor )
.getInterface( Ci.nsIDOMWindow );
var notificationBox = mainWindow.gBrowser.getNotificationBox();
notificationBox.appendNotification(
'This is my message',
'myNotifyId',
'chrome://global/skin/icons/information-16.png',
notificationBox.PRIORITY_INFO_LOW
);
});
Try:
If
documentmight be a frame, you would need to usedocument.defaultView.top.documentinstead.