Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to find out the URLs of the currently opened firefox tabs with a terminal command. Is there any possibility?

This way I would be able to write them into a text file and look at them lateron; and safe resources (I often have many open tabs). I know that there is an add-on for firefox, but I would be more confortable writing my own script.

share|improve this question
up vote 6 down vote accepted

The currently open URLs of the opened Firefox tabs are stored in sessionstore.js file which is located somewhere in $HOME/.mozilla/firefox/XXXXXXXX.default directory.

So, you can start from something like this:

cat $HOME/.mozilla/firefox/*default/sessionstore.js | sed "s/{/\n/g" | egrep -o '"url".*"scroll"' | cut -d\" -f4

Using cat we can display that file, and with the help of sed, egrep and cut we select only the URLs of the opened Firefox tabs from that file.

share|improve this answer
Double quotes needed for the egrep pattern in zsh. Other than that, nice tip, thanks :) – moon.musick Aug 28 '13 at 13:21
Would you like to describe in a few words how this command works? As I get it it is like: get content of the sessionstore.js, pipe to an operation to replace \" with \n and pipe to an operation to get all lines that begin with http? Is that right? What is the use of replacing \"? – aldorado Aug 28 '13 at 13:31
@moon.musick Or you can use bash -c 'cat $HOME/.mozilla/firefox/*default/sessionstore.js | sed "s/\"/\n/g" | egrep http[s]*:' and you will have no problem in any *sh. :) – Radu Rădeanu Aug 28 '13 at 13:32
@aldorado it displays the contents of sessionstore.js file, then replaces occurences of " with \n (a newline) and then filters out only lines containing http or https. Try displaying the file and you'll know why it needs newlines :) – moon.musick Aug 28 '13 at 13:35
In the file sessionstore.js there are not only the addresses of the open tabs. There are many other addresses. – Nicolas Barbulesco Oct 5 '13 at 9:04

That information is stored in $HOME/.mozilla/firefox/*default/sessionstore.js and its format is json.

The following example was made to work with PHP. It walks all firefox windows, all tabs and gets the relevant information which is the last entry inside of "entries". If we could use xpath to parse it, it would be something like: /windows/*/tabs/last()/url (my xpath knowledge is rusty).

You can copy/paste this code to a terminal:

cat $HOME/.mozilla/firefox/*default/sessionstore.js | php -r '
$json=json_decode(fgets(STDIN), TRUE);
foreach($json["windows"] as $w)
foreach($w["tabs"] as $t)
echo end($t["entries"])["url"]."\n";'

EDIT: With perl (but first, sudo apt-get install libjson-pp-perl) :

cat $HOME/.mozilla/firefox/*default/sessionstore.js | perl -e '
use JSON qw( decode_json );
my $json = decode_json(<STDIN>);
foreach my $w ( @{$json->{"windows"}} ) {
    foreach my $t ( @{$w->{"tabs"}} ) {
        print $t->{"entries"}[-1]->{"url"}."\n";
share|improve this answer
This answer uses the file sessionstore.js of Firefox. The problem is that is that this file notoriously loses tabs. What I want here is a parallel solution, asking Firefox what his tabs are. Like in AppleScript. – Nicolas Barbulesco Oct 5 '13 at 9:11
What do you mean by "loses tabs"? I'm currently running Firefox with 5 tabs and I see these 5 tabs when running these scripts. This solution walks all windows and all tabs of each window. – Hugo Vieira Oct 7 '13 at 13:37
I mean this. – Nicolas Barbulesco Oct 8 '13 at 12:39
The question posted by aldorado: (...) find out the URLs of the currently opened firefox tabs (...). You are talking about listing tabs that were saved after shutting down firefox. Also, that bug does not seem that notorious... – Hugo Vieira Oct 8 '13 at 13:08
i've tested both methods for the recovery.js-file with 9 windows and 840 tabs and they worked like a charm! -- just after piping the output into a text file i had to set the character map to ISO-8859-15 for the file of the perl-method...! – DJCrashdummy Nov 17 '15 at 21:43

Using bash I found the following answer. It requires only package: jq. It can be installed with: apt-get install jq

jq '.windows[].tabs[].entries[].url' ~/.mozilla/firefox/xkxwaf4z.default/sessionstore-backups/recovery.js

share|improve this answer

This is how you can extract the current URL of the front-most/active tab in Firefox:

cat recovery.js | php -r '$json=json_decode(fgets(STDIN), TRUE); $tindex = $json["windows"][0]["selected"]-1; $eindex = $json["windows"][0]["tabs"][$tindex]["index"]-1; echo $json["windows"][0]["tabs"][$tindex]["entries"][$eindex]["url"];'

Explanation: First, it finds the index of the active tab $tindex and then the index of the active history entry in this tab $eindex.

Every 15 seconds Firefox creates a backup in *default/sessionstore-backups/recovery.js.

share|improve this answer
php5-cli needs to be installed for this to work could you add that to your answer to improve. Is there a way to grab all of the tabs urls not just the front most? like the OP asks. – damien Mar 22 '15 at 9:05
I'm aware of the mismatch of the question and my answer, however Google will direct you here if you seek the information in my answer. – Lenar Hoyt Mar 22 '15 at 10:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.