{"id":357,"date":"2009-05-21T22:32:25","date_gmt":"2009-05-22T03:32:25","guid":{"rendered":"http:\/\/eligrey.com\/?p=357"},"modified":"2009-05-21T22:32:25","modified_gmt":"2009-05-22T03:32:25","slug":"jetpack-api","status":"publish","type":"post","link":"https:\/\/eligrey.com\/blog\/jetpack-api\/","title":{"rendered":"Jetpack API"},"content":{"rendered":"<p>Mozilla Labs&#8217; latest creation, <a href=\"https:\/\/jetpack.mozillalabs.com\/\">Jetpack<\/a>, is a great way to extend Firefox. It currently has a <a href=\"https:\/\/jetpack.mozillalabs.com\/api.html\">poorly documented <abbr title=\"Application Program Interface\">API<\/abbr><\/a> that doesn&#8217;t mention all of the public methods and fields. Due to Mozilla Labs&#8217; decision of not putting the API documentation on <a title=\"Mozilla Developer Center\" href=\"https:\/\/developer.mozilla.org\/\">MDC<\/a> or the <a href=\"https:\/\/wiki.mozilla.org\/\">MozillaWiki<\/a>, I cannot update the documentation myself. Therefore, I will list all of Jetpack&#8217;s documented and undocumented features as of version 0.1.2 in this blog post.<\/p>\n<h2>(Not) Assigning Properties<\/h2>\n<p>You can&#8217;t do things like <code>jetpack.tabs.focused.contentWindow.foo = \"bar\"<\/code>. I find this much too restrictive, as it hinders a developer&#8217;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&#8217;s <a href=\"https:\/\/developer.mozilla.org\/en\/XPCOM\">XPCOM<\/a> (<code>Components.*<\/code>, ect.) which means, with a little hacking, it may be possible to bypass this restriction. The follow code shows an example of getting an <code>nsIAlertsService<\/code> and using it instead of <code>jetpack.notifications.show<\/code>.<\/p>\n<pre lang=\"javascript\">var body = \"Some text\",\ntitle = \"Notification\",\nicon = \"http:\/\/code.eligrey.com\/favicon.ico\",\n\nclassObj = Components.classes['@mozilla.org\/alerts-service;1'],\nalertService = classObj.getService(Components.interfaces.nsIAlertsService);\n\nalertService.showAlertNotification(icon, title, body);<\/pre>\n<p><!--more--><\/p>\n<h2>Every Field &amp; Method<\/h2>\n<p>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 <code>[native code]<\/code>.<\/p>\n<ul>\n<li><code>location<\/code><\/li>\n<li><code>console<\/code>\n<ul>\n<li><code>info<\/code><\/li>\n<li><code>log<\/code><\/li>\n<li><code>arn<\/code><\/li>\n<li><code>error<\/code><\/li>\n<li><code>exception<\/code><\/li>\n<li><code>logFromCaller<\/code><\/li>\n<\/ul>\n<\/li>\n<li><code>$<\/code> and <code>jQuery<\/code>\n<ul>\n<li>All of the standard jQuery methods.<\/li>\n<\/ul>\n<\/li>\n<li><code>jetpack<\/code> and <code>Jetpack<\/code>\n<ul>\n<li><code>tabs<\/code> (the listed array methods are defined just to throw errors stating that they are unsupported)\n<ul>\n<li><code>focused<\/code>\n<ul>\n<li><code>onReady<\/code><\/li>\n<li><code>isClosed<\/code><\/li>\n<li><code>url<\/code><\/li>\n<li><code>contentWindow<\/code><\/li>\n<li><code>contentDocument<\/code><\/li>\n<li><code>raw<\/code> (the XUL <code>&lt;tab\/&gt;<\/code> element)<\/li>\n<li><code>focus<\/code><\/li>\n<li><code>close<\/code><\/li>\n<li><code>toString<\/code><\/li>\n<li><code>_unload<\/code><\/li>\n<\/ul>\n<\/li>\n<li><code>open<\/code><\/li>\n<li><code>toString<\/code><\/li>\n<li><code>onReady<\/code>\n<ul>\n<li><code>unbind<\/code><\/li>\n<\/ul>\n<\/li>\n<li><code>pop<\/code><\/li>\n<li><code>push<\/code><\/li>\n<li><code>reverse<\/code><\/li>\n<li><code>shift<\/code><\/li>\n<li><code>sort<\/code><\/li>\n<li><code>splice<\/code><\/li>\n<li><code>unshift<\/code><\/li>\n<li>tab indices (0, 1, 2, 3&#8230;) that follow the same structure as <code>jetpack.tabs.focused<\/code>.<\/li>\n<\/ul>\n<\/li>\n<li><code>unload<\/code><\/li>\n<li><code>notifications<\/code>\n<ul>\n<li><code>show<\/code><\/li>\n<\/ul>\n<\/li>\n<li><code>lib<\/code>\n<ul>\n<li><code>twitter<\/code>\n<ul>\n<li><code>Twit<\/code><\/li>\n<li><code>getStatus<\/code><\/li>\n<li><code>getTwitFriends<\/code><\/li>\n<li><code>getTwitInfo<\/code><\/li>\n<li><code>getTwitLatestStatus<\/code><\/li>\n<li><code>getTwitTimeline<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><code>statusBar<\/code>\n<ul>\n<li><code>append<\/code><\/li>\n<\/ul>\n<\/li>\n<li><code>track<\/code> (has to do with memory tracking)<\/li>\n<li><code>json<\/code> (No idea why this doesn&#8217;t follow Firefox 3.5&#8217;s JSON implementation naming at all)\n<ul>\n<li><code>encode<\/code><\/li>\n<li><code>decode<\/code><\/li>\n<\/ul>\n<\/li>\n<li><code>sessionStorage<\/code><\/li>\n<\/ul>\n<\/li>\n<li><code>setInterval<\/code><\/li>\n<li><code>clearInterval<\/code><\/li>\n<li><code>setTimeout<\/code><\/li>\n<li><code>clearTimeout<\/code><\/li>\n<li><code>addStatusBarPanel<\/code> (throws &#8220;addStatusBarPanel() has been moved to Jetpack.statusBar.append()&#8221;)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Mozilla Labs&#8217; latest creation, Jetpack, is a great way to extend Firefox. It currently has a poorly documented API that doesn&#8217;t mention all of the public methods and fields. Due to Mozilla Labs&#8217; decision of not putting the API documentation on MDC or the MozillaWiki, I cannot update the documentation myself. Therefore, I will list [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[15,48,90,96,111],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-browsers","tag-firefox","tag-javascript","tag-jetpack","tag-mozilla-labs"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pfpUD-5L","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/eligrey.com\/blog\/wp-json\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eligrey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eligrey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eligrey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eligrey.com\/blog\/wp-json\/wp\/v2\/comments?post=357"}],"version-history":[{"count":0,"href":"https:\/\/eligrey.com\/blog\/wp-json\/wp\/v2\/posts\/357\/revisions"}],"wp:attachment":[{"href":"https:\/\/eligrey.com\/blog\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eligrey.com\/blog\/wp-json\/wp\/v2\/categories?post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eligrey.com\/blog\/wp-json\/wp\/v2\/tags?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}