Recovering text areas from Firefox session information

By Uche Ogbuji
January 11, 2009 | Comments: 9

My style of browsing the Web has always been a mess of windows and tabs. I've always relied on tools to protect this messy model. Galeon has always had a built-in session saver, and I didn't switch to Firefox until I found a good session saver extension. Firefox 2 finally built in this feature. Usually a fair proportion of my mess of open pages are wiki pages and other Web forms in some partial state of completion. Thankfully Firefox's session saver also saves contents of text areas. But this isn't foolproof. Sometimes quirks or complexity in the server workflow mean cause inadvertent loss of text area information. For example, wikis with their own server-side session management might time you out of an editing session and trigger a redirect, replacing the text area restored by the browser with the last-saved version.

I've sometimes needed to recover lost changes in such situations. Unfortunately Firefox session files are a very ugly format. They are a bit of a JavaScript mess. Not JSON, because that would be too easy to deal with, I guess, and all without benefit of line breaks. I ended up writing a Python utility firefox_session_textareas.py (download) to extract the text area contents from these files. There isn't much to it. The only tricky bit was getting the regular expression right.

If I want to browse through all the text areas in a saved session, I can just invoke it as follows:

python firefox_session_textareas.py "/Users/uche/Library/Application Support/Firefox/Profiles/$PROFILE-ID/sessionstore.js"

If I specifically want to look for a URL, or page title, or a particular string from text area contents, I can specify it as a second command line parameter, for example:

python firefox_session_textareas.py "/Users/uche/Library/Application Support/Firefox/Profiles/$PROFILE-ID/sessionstore.js" Sightings

And it will only show the instances including the string "Sightings". For each match, you get something like the following:


------------ firefox_session_textareas.py - http://wiki.xml3k.org/Sightings?action=edit ------------

These are Web/media mentions of xml3k tools. Avoid mentions that don't add new info, e.g. a mirroring of existing resources. But if something indicates someone or some project is using an xml3k, even fleetingly, it's worth adding.


* [http://rss-atom-guide.blogspot.com/2007/12/gathering-tools.html "RSS and Atom Feeds Tricks: Gathering Tools"] - Uses 4Suite as a key tool, though an older version
* [http://blog.erikisaksson.com/2008/03/08/pebble-migration/ "Pebble Migration"] - "In order to migrate this weblog from Pebble 2.2 to WordPress 2.3.3, I created a small, quick-and-dirty migration script." Uses 4Suite
* [http://feihonghsu.blogspot.com/2007/10/why-net-programmers-should-care-about.html "Why .NET Programmers Should Care About Python"] - Nice Amara tutorial

Another technique I find useful with Firefox is to periodically copy the session file sessionstore.js. Even though I have Time Machine on Mac, it would be far too awkward to restore a session file that way. It's easier to keep snapshots, and then I can always use firefox_session_textareas.py whenever I need to recover text area information from the past.

Update: I updated this program to work in Firefox 3.5, which changed the stored session JS format. The main location for this tool is now in this repository, and specifically at: http://bitbucket.org/uche/scatter-share/src/tip/firefox_session_textareas.py (use the "raw" link to download).


You might also be interested in:

9 Comments

hi sorry i am completely lost
what am i supposed to do to find the text i lost?

Hmm, I wonder whether you have much of a technical background. To be honest, this might not be the easiest tool for the average user. It would be nice for someone to create an end-user tool to protect partial work in text areas.

Anyway, first step is to find your sessionstore.js, and preferably copy it to somewhere safe. Where this file is depends on your platform, how you installed Firefox, etc.

Then you need the Python programming language: http://python.org

Install that open up a command line, and run the command in the posting, using the location where you copied sessionstore.js.

HTH.

Thank you !
i thought ff stores the temporary textarea stuff in memory only. Now i was able to recover the content i lost :) - ok with an editor not with your script - but i will give it a try with ruby
best
paul

Another approach is to use a good clipboard manager, and just select all/copy every now and then. Here is a good roundup of clipboard managers for Mac. FWIW I wound up with ClipMenu and am liking it so far.

http://theappleblog.com/2009/06/02/10-clipboard-managers-for-os-x/

Linux options include:

* http://parcellite.sourceforge.net/
* http://sourceforge.net/projects/glipper/

Before half an hour i accidentally closed the page and lost all the textarea content i had.

Now I try to use your script with my Mac terminal but I can't get to a final solution.

Could you please tell me how to correctly run the script so i will get the visible session information?

Chris, sorry about the delay. Lots of travel. I hope you copied the session JS file right away. You might be using a Firefox 3.5 preview. When I checked I realized my original code was not working for 3.5. I updated it to support 3.0 and 3.5. Download the new version here:

http://bitbucket.org/uche/scatter-share/raw/tip/firefox_session_textareas.py

Hey,
The same kind of thing happened to me in Safari, i answered fifty essay questions with paragraph answers, but when i went to save, the computer said i was logged out and i lost everything i wrote. Does the trick you mentioned work with Safari? Any help would be really really appreciated.

Hi Alex,

I'm so sorry, that sounds awful! I personally do not know whether there is any such trick for Safari, but I wish you the best of luck.

I keep getting this error:

HEADING_TPL%match.group(1)

on line 36

how do I fix this?

News Topics

Recommended for You

Got a Question?