Plain bootstrapped add-ons are the most complicated ones to create, because you basically have to do a lot of the things yourself that XUL or Add-on SDK add-ons more or less get for free. (Actually the SDK is not much more than a fat layer on top of bootstrapped add-ons). So unless you're willing to learn a ton of Gecko / toolkit / Firefox internals, you should prefer XUL overlay add-ons or SDK add-ons to bootstrapped ones.
To answer your question: You have to create the XUL elements (e.g. a <menuitem>
) using the regular DOM API, so something like this:
// Provided you already obtained a reference to some |window|
var document = window.document;
var contextMenu = document.getElementById("contentAreaContextMenu");
var menuItem = document.createElement("menuitem");
menuItem.setAttribute("label", "my item");
contextMenu.appendChild(menuItem);
menuItem.addEventListener("command", function() {
window.alert("clickety-click");
}, false);
You'll also have to write some code that ensures the menu item and listener are removed when the window is closed (to avoid leaking the window) or when your add-on is disabled/removed (to avoid leaving a mess behind).
I suggest you have a look at other bootstrapped add-ons. E.g. restartless-restart is pretty small add-on that shouldn't be too hard to follow, but that also adds a toolbar button and menu item, among other things. Disclaimer: I contributed to that add-on a bit, but it is not "mine".
I myself ended up writing a small toolset to help me create add-ons which I called extsdk, because I disliked the SDK for being too fat and limited (the SDK situation improved somewhat since then).