Getting started
with Mozilla's Add-on SDK
FSOSS, October 29th 2011
FSOSS, October 29th 2011
Published roadmap: https://wiki.mozilla.org/Jetpack/Roadmap
Mozilla Labs projects currently using the SDK:
Mozilla adds features to Firefox via add-ons, using the SDK
Requirements:
Set-up
cd /path/to/SDKsource bin/activateBasic JS style similar in feel to Node.js
Example:
var someModule = require("some-module");
var instance = someModule.someClass({
thisoption: 'my option',
thatoption: 42,
onSomeEvent: function(data) {},
});
instance.someMethod();

var data = require("self").data;
var pageMod = require("page-mod").PageMod({
include: ['http://talks.canuckistani.ca/*'],
contentScript: 'if (confirm("EXTERMINATE???")) ' +
'{ document.body.innerHTML = ' +
'\'<img src="http://dailypop.files.wordpress.com/2010/04/dalek.gif">\';' +
'document.body.style.display="block"; ' +
'};',
contentScriptWhen: 'end',
});
Link
include: ['http://talks.canuckistani.ca/*']contentScript: "..."contentScriptWhen: 'end'
var cm = require("context-menu");
cm.Item({
label: "Context Menu Test",
context: cm.URLContext('http://aer.local:8080/fsoss*'),
contentScript: 'self.on("click", function (node, data) {' +
' alert("Click on context menu!"); ' +
'});',
onMessage: function() {
tabs.activeTab
}
});
require("widget").Widget({
id: "mozilla-icon",
label: "This is the widget demo!",
contentURL: "http://www.mozilla.org/favicon.ico",
panel: xPanel
});
var xPanel = require("panel").Panel({
height: 340,
width: 600,
contentURL: 'http://www.reddit.com/r/programming/.compact'
});
content script:
$("#panelify").click(function() {
self.port.emit('panelify', true);
return false;
});
main.js:
var xPanel = require("panel").Panel({
height: 340,
width: 600,
contentURL: 'http://www.reddit.com/r/programming/.compact'
});
/* pop up the panel */
worker.port.on('panelify', function(m) {
xPanel.show();
});
var shorten = function(url, callback) {
let requestJSON = JSON.stringify({longUrl: url});
let googlRequest = require("request").Request({
url: 'https://www.googleapis.com/urlshortener/v1/url',
content: requestJSON,
contentType: 'application/json',
onComplete: function(response) {
callback(response.json);
}
});
googlRequest.post();
}
content script:
$("#notify").click(function() {
self.port.emit('notify', true);
return false;
});
main.js:
worker.port.on('notify', function(m) {
require("notifications").notify({
title: "hello from Growl!",
text: "of course, you need Growl installed for this to work...",
iconUrl: "http://www.mozilla.org/favicon.ico"
});
});