Extracting open URLs from sessionstore.js?

User Help for Mozilla Firefox
moler
Guest

Re: Extracting open URLs from sessionstore.js?

Post by moler »

What is the file size of your sessionstore.js and sessionstore.bak - in other words, if they are empty there is nothing to restore and the bookmark won't work.
Frebu
Guest

Re: Extracting open URLs from sessionstore.js?

Post by Frebu »

Both are 709KB and If I open them in notepad I can see the web pages
User avatar
dickvl
Posts: 54145
Joined: July 18th, 2005, 3:25 am

Re: Extracting open URLs from sessionstore.js?

Post by dickvl »

Maybe the tabs aren't stored as open tabs, but are closed tabs.
Did you try the second code as well?

Code: Select all

javascript:(function(){var D=document,H,i=j=0,P=D.getElementsByTagName('PRE'),t=[],R=/"state":\{"entries":\[\{("url":"([^"]*)")\,("title":"([^"]*)"){0,1}/g,T,U;for(j=0;E=P[j];j++){H=E.innerHTML;while(R.exec(H)){U=RegExp.$2;T=RegExp.$4;if(T.length==0){T=U;}t.push('<b>['+(++i)+']</b> <a href='+U+'>'+T+' ('+U+')<\/a>');}}with(window.open().document){open();close();body.innerHTML=t.join('<br>\n');}})();
Paloseco
Posts: 60
Joined: October 4th, 2004, 8:06 am

Re: Extracting all URLs from sessionstore.bak

Post by Paloseco »

Several commands are available on this page:

Extract all urls from the last firefox sessionstore.js file used

This one worked for me:

Code: Select all

perl -lne 'print for /url":"\K[^"]+/g' sessionstore.bak


NOTE that the sessionstore.bak although is a backup can be overwritten unintentionally if you reopen the firefox after a crash or power cut.

If there has been a power cut or poweroff you can try looking into recovered files if you selected to test hard drive when windows starts up:

Code: Select all

perl -lne 'print for /url":"\K[^"]+/g' c:\found.000\file0000.chk
kittykittymeow
Posts: 3
Joined: May 25th, 2011, 3:58 pm

Re: Extracting open URLs from sessionstore.js?

Post by kittykittymeow »

georgd wrote:Hi all, I extended the HTML-file by ZeePrime so it shows also closed windows, contains some help, and is more readable. It is different from the bookmarklet as it does not change the current session and also handles closed windows.

I uploaded the file to http://rapidshare.com/files/443154522/F ... r_v1.0.htm as I did not find any possiblity to add files here in the board. Feel free to extend or update it, e.g. add loading a sessionstore.js-file (has to to reside in the same directory as the html file). Cheers, Georg


This download is now gone :(

magoood wrote:
0rsted wrote:I wrote a simple parser (that actually works) in asp and uploaded it to my server

http://server.oe-web.dk/sessionstore.asp

Paste the content of the sessionstore.js file into this, and make your selections, then you can see the tabs and the windows of the session

Could you please re-upload this to another server because the site is not working. I need it because of the same problem reported in this thread (FF crashed and I want to extract the URLs from the useless corrupted sessionstore.js)


Seconded, this page no longer exists either :(


A page that converts the files to be laid out like this:
| tab 1 | tab 2 | tab 3 |
--
| link1 | link1 | link1 |
| link2 | link2 | link2 |
| link3 | link3 | link3 |

would be really good, I can open the sessionstore.js in Notepad but it is very fiddly to read and even more if I want to actually open the links from it copypasting each one by hand (I had about 100 tabs open when firefox crashed, and when it re-opened and asked if I wanted to restore I think I must have clicked the wrong button by mistake I'm so used to firefox crashing on me hehe)
User avatar
therube
Posts: 21703
Joined: March 10th, 2004, 9:59 pm
Location: Maryland USA

Re: Extracting open URLs from sessionstore.js?

Post by therube »

(I'm on Win7, no -nix shell, & had trouble with much of the examples, escaping & piping & single & double quotes & ...)

Anyhow this is what I came up with.

Code: Select all

sed -e "s/\[{/\n/g" -e "s/}, {/\n/g"  SESSIONSTORE.JS  |  sed "s/.url.:./\n/g"  |  grep "^http" | sed "s/\",\".*//"  >  ZOUT


The first part I don't really understand & just copied verbatim from one of the posts.
Then I started running into escaping issues & whatnot, so in some places, I simply used a . (dot) instead of \".
And then \n is different from \r, depending on might be considered a "newline".
The last sed did work with escaping. (Perhaps the first did not because the line started with a quote?)


Also note that the way I did it, I came up with a LOT more URLs compared to some of the other methods (or at least in my earlier attempts to hack through some of the other methods).
In my case, 3705 vs 1485.

Also URLs like ftp:// are not included at all, nothing other then http?:.

Oh, & dickvl javascript: functions haven't worked for me in a long time (assuming I was attempting them correctly).


(Don't you just love black boxes ;-).)
Fire 750, bring back 250.
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball CopyURL+ FetchTextURL FlashGot NoScript
morat
Posts: 6404
Joined: February 3rd, 2009, 6:29 pm

Re: Extracting open URLs from sessionstore.js?

Post by morat »

@kittykittymeow

Here is an example that works for me in scratchpad in the browser environment.

Instructions:

1. open about:config
2. set devtools.chrome.enabled to true
3. tools > web developer > scratchpad
4. environment > browser
5. edit > paste (i.e. copy and paste code below)
6. execute > run

or

1. tools > web developer > error console
2. paste code in text field
3. evaluate code

Notes:

* cancel the file picker to read a session store file in the profile folder
* install the dom inspector extension to inspect the json object (optional)
* save page with links - file > save page as > web page, complete
* save page with urls - file > save page as > web page, html only

Code: Select all

function linkify(event) {
  var re = RegExp("\\bhttps?://[^\\s]+", "gi");
  var doc = event.originalTarget;
  var node = doc.getElementsByTagName("pre")[0].firstChild;
  var text = node.nodeValue;
  if (re.test(text)) {
    var span = doc.createElement("span");
    var m, p = 0;
    re.lastIndex = 0;
    node.parentNode.replaceChild(span, node);
    while ((m = re.exec(text))) {
      var a = doc.createElement("a");
      a.target = "_blank";
      a.style.color = "#006620";
      a.style.backgroundColor = "#fff9ab";
      a.href = m[0];
      a.appendChild(doc.createTextNode(m[0]));
      span.appendChild(doc.createTextNode(text.substring(p, m.index)));
      span.appendChild(a);
      p = re.lastIndex;
    }
    span.appendChild(doc.createTextNode(text.substring(p)));
    span.normalize();
  }
}
var win;
if (typeof gBrowser == "undefined") {
  win = top.opener; /* Error Console */
} else {
  win = window; /* Scratchpad */
}
var fp = Components.classes["@mozilla.org/filepicker;1"].
  createInstance(Components.interfaces.nsIFilePicker);
fp.init(win, "Open File", Components.interfaces.nsIFilePicker.modeOpen);
fp.appendFilter("Session Store Files", "*.bak; *.js; *.json");
fp.appendFilter("JSON Files", "*.json");
fp.appendFilter("JS Files", "*.js");
fp.appendFilter("BAK Files", "*.bak");
var file;
if (fp.show() == Components.interfaces.nsIFilePicker.returnOK) {
  file = fp.file;
} else {
  var info = Components.classes["@mozilla.org/xre/app-info;1"].
    getService(Components.interfaces.nsIXULAppInfo);
  var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
    getService(Components.interfaces.nsIPromptService);
  var fileExtension = info.name == "SeaMonkey" ? "json" : "js";
  var parentWindow = null;
  var title = "Open File";
  var description = "Open sessionstore." + fileExtension + " or sessionstore.bak";
  var flags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING +
    ps.BUTTON_POS_1 * ps.BUTTON_TITLE_IS_STRING +
    ps.BUTTON_POS_2 * ps.BUTTON_TITLE_IS_STRING;
  var btn0 = fileExtension.toUpperCase();
  var btn1 = "Cancel";
  var btn2 = "BAK";
  var message = null;
  var state = {value: false};
  var choice = ps.confirmEx(parentWindow, title, description, flags, btn0, btn1, btn2, message, state);
  var dirService = Components.classes["@mozilla.org/file/directory_service;1"].
    getService(Components.interfaces.nsIProperties);
  file = dirService.get("ProfD", Components.interfaces.nsILocalFile);
  if (choice == 0) file.append("sessionstore." + fileExtension);
  if (choice == 2) file.append("sessionstore.bak");
}
if (file.exists() && file.isFile() && file.isReadable()) {
  var fis = Components.classes["@mozilla.org/network/file-input-stream;1"].
    createInstance(Components.interfaces.nsIFileInputStream);
  fis.init(file, 0x01, 0, 0);
  var fileSize = fis.available();
  var cis = Components.classes["@mozilla.org/intl/converter-input-stream;1"].
    createInstance(Components.interfaces.nsIConverterInputStream);
  cis.init(fis, "UTF-8", fileSize, Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
  var data = new Object();
  cis.readString(fileSize, data);
  cis.close();
  var jsonObject = JSON.parse(data.value);
  if (typeof win.inspectObject != "undefined") win.inspectObject(jsonObject); /* DOM Inspector */
  var out = new Array();
  out.push("Session Store Link Extractor");
  for (var i = 0, windows = jsonObject.windows; i < windows.length; i++) {
    for (var j = 0, tabs = windows[i].tabs; j < tabs.length; j++) {
      out.push("^ window " + (i + 1) + " tab " + (j + 1) + " entries " + tabs[j].entries.length);
      for (var entries = tabs[j].entries, k = entries.length - 1; k >= 0; k--) {
        out.push((entries[k].title || "Not available") + "\n" + entries[k].url);
      }
    }
  }
  var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].
    createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  converter.charset = "UTF-8";
  for (var i = 0; i < out.length; i++) {
    out[i] = converter.ConvertFromUnicode(out[i]);
    out[i] = out[i].replace(/&/g, "&amp;");
    out[i] = out[i].replace(/>/g, "&gt;");
    out[i] = out[i].replace(/</g, "&lt;");
    out[i] = out[i].replace(/"/g, "&quot;");
    out[i] = out[i].replace(/'/g, "&apos;");
  }
  var data = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">';
  data += "<html><head><title>" + out[0] + "</title>";
  data += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
  data += "</head><body><pre>" + out.join("\n\n") + "</pre></body></html>";
  var browser = win.gBrowser.getBrowserForTab(
    win.gBrowser.selectedTab = win.gBrowser.addTab("data:text/html;charset=utf-8;base64," + btoa(data)));
  browser.addEventListener("load", function (event) {
    browser.removeEventListener("load", arguments.callee, true);
    linkify(event);
  }, true);
}

Reference:

nsSessionStartup.js [mxr.mozilla.org]
Last edited by morat on June 29th, 2012, 11:50 pm, edited 8 times in total.
kittykittymeow
Posts: 3
Joined: May 25th, 2011, 3:58 pm

Re: Extracting open URLs from sessionstore.js?

Post by kittykittymeow »

thanks a lot, did you use to run the MORAT.net website by any chance? I had my personal website there when I was little at school and a few years back I came and looked and it was all goneee

I also found a trick I should have thought of already, you can force Firefox to read any sessionstore.js file if you put it in the current profile's directory and go to about:sessionrestore, and that way you can view the links in firefox like normal. But of course it's not as good as a plain list of links if you don't want to open most of them but only some of them, since Firefox's sessionrestore for some reason only tells you the page name not the links and often pages have the same page name
morat
Posts: 6404
Joined: February 3rd, 2009, 6:29 pm

Re: Extracting open URLs from sessionstore.js?

Post by morat »

kittykittymeow wrote:thanks a lot

You're welcome.

kittykittymeow wrote:did you use to run the MORAT.net website by any chance?

Nope. I got my user name from a science fiction novel.

http://en.wikipedia.org/wiki/The_Player_of_Games
User avatar
therube
Posts: 21703
Joined: March 10th, 2004, 9:59 pm
Location: Maryland USA

Re: Extracting open URLs from sessionstore.js?

Post by therube »

Neat. That works. (Would have never figured it out myself.)

Just to point out, SeaMonkey still uses the .json extension for sessionstore, so sessionstore.json.

So if you use that code for SeaMonkey (which does work), you either need to adjust it to also include .json, or you would need to enter something like *.json (or simply sessionstore.json) in the file picker dialog box.

(SeaMonkey does not have Scratchpad, yet, so you'd need FF to handle that aspect of it.)
Fire 750, bring back 250.
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball CopyURL+ FetchTextURL FlashGot NoScript
morat
Posts: 6404
Joined: February 3rd, 2009, 6:29 pm

Re: Extracting open URLs from sessionstore.js?

Post by morat »

@therube

I tweaked the code to work with Firefox and SeaMonkey in both the Scratchpad and Error Console windows. In SeaMonkey, you can use the Error Console window to evaluate the code.
User avatar
therube
Posts: 21703
Joined: March 10th, 2004, 9:59 pm
Location: Maryland USA

Re: Extracting open URLs from sessionstore.js?

Post by therube »

Works well, thank you :-).
Fire 750, bring back 250.
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball CopyURL+ FetchTextURL FlashGot NoScript
User avatar
gssq
Posts: 504
Joined: December 7th, 2002, 10:17 am
Location: Singapore
Contact:

Re: Extracting open URLs from sessionstore.js?

Post by gssq »

My sessionstore got corrupted so I'm doing this manually (the other solutions I found didn't work - I think sessionstore.js got corrupted which was why FF didn't load it in the first place)

I replaced all instances of "url":" with "^p^p"url":"" (2 new paragraphs).

And then I search for lines with ""title":" as there're many nonsense lines going to Facebook/Twitter/about:blank/Google+ pages

Hope this helps others

I need to use a Session Manager to save my last few sessions...
VGR
Guest

Re: Extracting open URLs from sessionstore.js?

Post by VGR »

Hi all, great thread here - found a lot of useful info. Thanks to all the contributors so far.

An alternative to extracting urls from a corrupted sessionrestore.js file altogether is to restore a previous version of the sessionrestore.js file. The below instructions target the Windows Vista or Windows 7 operating systems. This can be helpful especially if the session you seek is from previous sessions, as a poster asked about earlier. Link to instructions here:
Using Vista/Windows 7 Previous Versions to Restore Files You Thought You'd Lost - Jon Galloway

Hope this is helpful,
VGR
marketpromo
Guest

Re: Extracting open URLs from sessionstore.js?

Post by marketpromo »

VGR wrote:Hi all, great thread here - found a lot of useful info. Thanks to all the contributors so far.

An alternative to extracting urls from a corrupted sessionrestore.js file altogether is to restore a previous version of the sessionrestore.js file. The below instructions target the Windows Vista or Windows 7 operating systems. This can be helpful especially if the session you seek is from previous sessions, as a poster asked about earlier. Link to instructions here:
Using Vista/Windows 7 Previous Versions to Restore Files You Thought You'd Lost - Jon Galloway

Hope this is helpful,
VGR


I thought I lost my 70 tabs and I wasted nearly a whole day trying to recover my overwritten sessionstore.js and .bak files, installed the Recuva program to search for good/excellent copies of the old files and thought I found some but they turned out to be corrupted after I copied them into the profile folder. I tried viewing the js files in a text editor and using Firefox javascript but did not know how to use it and I could not easily find my open tab links, there was just a lot of code that I don't understand, and I could search for old tab urls but that would take forever to find each one. Stupid me! I should have read the last page of this forum to find out the latest solutions and it turns out that VGR's last post was my solution, I had no idea that my Vista Ultimate had the Shadow Copy utility running in the background, I simply right clicked on the sessionstore.js and sessionstore.abk files in the profile folder, selected Properties and clicked the tab Previous Versions and waited for it to find good copies of each file from the past few days, and VOILA the files brought back my 70 tabs. Now I installed session Manager app for Firefox to save them all. Thank You VGR!
Locked