Eli Grey

Jetpack API

Mozilla Labs’ latest creation, Jetpack, is a great way to extend Firefox. It currently has a poorly documented API that doesn’t mention all of the public methods and fields. Due to Mozilla Labs’ decision of not putting the API documentation on MDC or the MozillaWiki, I cannot update the documentation myself. Therefore, I will list all of Jetpack’s documented and undocumented features as of version 0.1.2 in this blog post.

(Not) Assigning Properties

You can’t do things like jetpack.tabs.focused.contentWindow.foo = "bar". I find this much too restrictive, as it hinders a developer’s ability to make an API for a webpage to communicate with a jetpack to do things that need more privileges. Ironically, it seems that jetpacks have full access to Firefox’s XPCOM (Components.*, ect.) which means, with a little hacking, it may be possible to bypass this restriction. The follow code shows an example of getting an nsIAlertsService and using it instead of jetpack.notifications.show.

var body = "Some text",
title = "Notification",
icon = "http://code.eligrey.com/favicon.ico",
 
classObj = Components.classes['@mozilla.org/alerts-service;1'],
alertService = classObj.getService(Components.interfaces.nsIAlertsService);
 
alertService.showAlertNotification(icon, title, body);

Every Field & Method

The following is every enumerable field and method that I found in the jetpack API. You can see what arguments a function takes and how it works by just converting it to a string as these functions will show their code bodies and not just [native code].

  • location
  • console
    • info
    • log
    • arn
    • error
    • exception
    • logFromCaller
  • $ and jQuery
    • All of the standard jQuery methods.
  • jetpack and Jetpack
    • tabs (the listed array methods are defined just to throw errors stating that they are unsupported)
      • focused
        • onReady
        • isClosed
        • url
        • contentWindow
        • contentDocument
        • raw (the XUL <tab/> element)
        • focus
        • close
        • toString
        • _unload
      • open
      • toString
      • onReady
        • unbind
      • pop
      • push
      • reverse
      • shift
      • sort
      • splice
      • unshift
      • tab indices (0, 1, 2, 3…) that follow the same structure as jetpack.tabs.focused.
    • unload
    • notifications
      • show
    • lib
      • twitter
        • Twit
        • getStatus
        • getTwitFriends
        • getTwitInfo
        • getTwitLatestStatus
        • getTwitTimeline
    • statusBar
      • append
    • track (has to do with memory tracking)
    • json (No idea why this doesn’t follow Firefox 3.5’s JSON implementation naming at all)
      • encode
      • decode
    • sessionStorage
  • setInterval
  • clearInterval
  • setTimeout
  • clearTimeout
  • addStatusBarPanel (throws “addStatusBarPanel() has been moved to Jetpack.statusBar.append()”)

Leave a Reply