Subscribe to our mailing list

* indicates required

Tuesday, August 25, 2009

Using Mozilla Jetpack to save tab ensembles

I haven't played with Jetpack all that much since I last wrote about it. I did write a script that collects all the URLs and page titles of all open Firefox tabs and displays them in a table, so that I can Save the table and be able to return to a given tab configuration any time I want. Right now I just save the page to disk manually. But a proper implementation would use Jetpack's persistence API (and a nice UI) to make the process easier.

But that got me thinking. Why is it Firefox doesn't already offer this capability? First let's define what we're talking about. I'm thinking there should be a special name (an agreed-upon technical term) for a particular collection of open tabs in a browser. The name I propose is simply ensemble. At the moment, I have 4 tabs open in Firefox: The Blogger editing window, Twitter's Search page, the Mozilla Jetpack contest page, and Google. I should be able to Save this configuration off as a named collection; let's call it "The tabs for that Jetpack followup blog." That's an ensemble.

Tomorrow at this time I might very well have 20 tabs open, including, several CMS Watch pages, Central Desktop (which we use a lot at CMS Watch), Files Anywhere (ditto), Google Calendar, Gmail, and who knows what else. At the moment, in my day job, I'm doing a bit of writing about Oracle Universal Content Management, and yesterday I had six different PDFs (UCM documentation) open in Firefox tabs, plus all the usual nonsense. I'd like to be able to capture all of those tabs as one named collection, one ensemble, that I can passivate (and reanimate later, at my leisure).

Am I missing something? Can Firefox already do this? Yes yes, I realize that I can quit Firefox and have my current tab configuration saved for the next time I start Firefox, but that's not at all the same as saving off different named, tagged ensembles (saving them at any time, not just quitting time) that I can choose to reinstate later.

I know there are services out on the Web where I can dump collections of bookmarks. That's not what I want. I want to do everything from within Firefox.

At any rate, the code I'm using right now to get the titles and URLs of all open tabs and display them in a table onscreen looks like this:

jetpack.tabs.onReady( renderTabList );

function renderTabList( doc ) {

var TRIGGER_PAGE = "tabs.htm";
var tabs = jetpack.tabs;
var currentUrl = doc.location.href;

if ( currentUrl.indexOf( TRIGGER_PAGE ) == -1 )
return; // only fire when tabs.htm loads

var markup = "<table>";

for ( var i = 0; i < tabs.length; i++ ) {

var title =
$( tabs[ i ].contentDocument ).find( "title" ).text( );

var url = tabs[ i ].url;

if ( url.indexOf( TRIGGER_PAGE ) != -1 ||
url.indexOf( "about:") != -1 )
continue; // don't include ourselves

function shorten( str, limit )
str.length > limit ?
str.substring( 0, limit ) + "... " : str;

title = shorten( title, "... " );

var visibleUrl = shorten( url, "... " );

markup += "<tr>";
markup += "<td>" + title + "</td>";
markup += "<td>" + url ) + "</td>";
markup += "</tr>";

markup += "</table>";

$( doc ).find( 'div' ).html( markup );

It's ugly code and I'm sure it can be improved in a hundred different ways, but hey, it's just a proof of concept, so if it blows up no one loses their hands.

I wrote the shorten( ) macro, btw, before I realized Jetpack had an ellipsify() method.

In conjunction with the script, I use a dummy HTML page called tabs.htm that just contains a single <div> in the body. That's where I attach the table of results.

Nothing special, I know.

How about you? Have you written any Jetpack code lately? (Are you entering the contest?) If so, please tell me about it. I'd like to know what you're doing and what your impressions are of Jetpack so far. My overall impression of Jetpack remains positive. I'm anxious to see where it'll take us next.


  1. Anonymous12:35 PM

    You can 'Bookmark all tabs', which saves a bookmark to the current set of tabs.

  2. Anonymous3:48 PM

    Agree with Anonymous,

    Which makes a bookmark group. Then you can, in that group's sub-menu, "Open All in Tabs".

    Been there for years.

    Still, great use for Jetpack. This allows new possibilities, such as sharing tab groups.

  3. Jetpack is modelled very closely off Chrome Extensions. I used Chrome Extensions to write an extension that uses AtomPub to post browser history to an Atom feed.

    Part two was to write a daemon to monitor the Atom feed and to generate dot language graphs of my browsing history, which automatically regenerated a graphviz visualization of my history.

    presentation for Moz Summer Design Challenge:

  4. Also, I petitioned Opera and finally got a feature to let me save "an ensemble" of tabs: you can export all the tabs within a current window. In practice, its pretty easy to find the related content, shove it into one window, and then save that window. I tend to keep about 30-40 windows exported with reference material for various projects & endeavours, ready to be opened on demand. I demonstrate this capability in my presentation for Moz Summer Design Challenge.

  5. I'd rather have a version of FF that didn't crash, which would obviate the use case.

  6. It's weird that this is becoming a pattern.
    I got tired of using bookmarks (because I never clean them) so I wrote a quickly one-off RoR app to allow me to sort and filter my links by subject matter on a tab.

  7. Anonymous1:01 AM

    This is exactly the kind of behavior I am searching for. I'm amazed that I can find many examples of complicated tab customization or session save-on-exit applications, but nothing as simple as this. Many of the solutions seem a solution in search of a problem to solve.

  8. I've had similar thoughts but I would like to see it extended to the entire desktop. The best descriptive term I can come up with is "project" where a project is a named collection of apps, windows, open files, currently allowed contacts (i.e. the people I'm working on this project with) that are the only ones allowed through to communicate when I'm working on this particular project (with prioritizable exceptions). A project could be opened on a virtual desktop and with a few open, it would be easy to switch between them and yet still focus on each one. Also, the recoverability would be very nice.

    These are half-formed thoughts and very possibly a solution in search of a problem, too.

  9. I want to use something similar to the above to port a big ensemble of tabs from Firefox to Google Chrome.

    There appear to be several potential methods

    1. Export firefox session manager, import into chrome session saver

    --I see no support for this on either side, and it seems unlikely to be supported.

    2. 'Bookmark all tabs' in firefox and somehow transfer from firefox to chrome.

    --for starters, a big problems is that bookmarks are saved in binary form in the file places.sqlite on the firefox side.

    3. Write a custom script to dump all tab URLs, and generate a portable java script that will open the same windows+tabs on the chrome side.

    What is the best direction to take here? I freely admit I'm not good at javascript no expert on the innards of Mozilla nor Chrome.

  10. Kas,

    Would you mind educating me on how to RUN your code snippet? I stuck it in a file called renderTabList.htm and opened it. nothing happened.


Add a comment. Registration required because trolls.