Skip to content

Getting a list of your Firefox tabs

Just a quick Perl hack I put together last night. This "oneliner" reads the sessionstore.js file and prints the URLs of all tabs you're currently looking at. I also noticed that the sessionstore contains lots of other useful information, including all session cookies. I'm quite sure that will come in handy some day. :-D I took a quick look for code that does this, and found people trying to put some complicated grep/regex together, but that seemed way too fragile to me. One person did it in JavaScript (which makes a lot of sense since the session store is encoded as a JavaScript data structure), and I decided to go that way as well except I'm using Perl's JavaScript module so it can still run on the command-line. :-)

CODE:
#!/usr/bin/perl

use JavaScript;

my $rt = JavaScript::Runtime->new();
my $cx = $rt->create_context();

$cx->bind_function(fetch => sub { print( $_[0] . "\n" ); });

$sess = `cat ~/.mozilla/firefox/*.default/sessionstore.js`;

$sessparser = <<EOF;
for( var win_ in sess['windows'] )
{
win = sess['windows'][win_];
for( var tab_ in win['tabs'] )
{
tab = win['tabs'][tab_];
fetch(tab['entries'][tab['index'] - 1]['url']);
}
}
EOF

$cx->eval('var sess = ' . $sess . ';' . $sessparser);


And yes, my code is indented, but my shitty blog software likes to break it.

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment