Extracting open URLs from sessionstore.js?

User Help for Mozilla Firefox
QonoS
Posts: 234
Joined: February 11th, 2003, 8:09 pm

Extracting open URLs from sessionstore.js?

Post by QonoS »

Platform: Mac OS X 10.3.9
Firefox 2.0.0.11

On a few occasions I've had a bad FF crash or hang that requires a kill (Force Quit) to resolve. I have FF set to restore tabs after a normal exit or a crash, but of course sometimes restoring the session reproduces the crash/hang conditions.

Often I have a pretty good idea of which open page closed the crash. It would sure be nice to just delete that offending page and restore the rest.

This is a trivial process with Camino, a Mac OS X-only Mozilla/Gecko browser, because it uses the Mac OS X .plist format, which is easily editable with an Apple-supplied tool. sessionstore.js, otoh, appears to be in xml format (nope, edit below), and is not easily editable or readable in a text editor, although I'm sure the XML-savvy (which I am not) could do so.

Is there a good tool (that runs on OS X 10.3.x) for extracting sessionstore.js info or for reading sessionstore.js files in a structured format, to minimize the work involved in extracting the open URLs from the file in the event of a crash? I did use a text editor to do it, once, but it was extremely tedious and I'm not sure I caught what I wanted to catch. The file appears to capture, not only the main URL of an open page, but any child URLs contained within that page. I'm sure there's a good reason for this, but it does make things difficult for what I'm trying to do.

Edit: Oops, I just noticed it's in JSON, not xml format according to the KB page. So I guess I want a tool that can read that format and present its contents in an easily-grasped, structured format, or extract data from it.
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Post by trolly »

Why not open it in a text editor?
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
QonoS
Posts: 234
Joined: February 11th, 2003, 8:09 pm

Post by QonoS »

trolly wrote:Why not open it in a text editor?


WADR, did you miss this part of my post?

QonoS wrote:I did use a text editor to do it, once, but it was extremely tedious and I'm not sure I caught what I wanted to catch.


Have you seen what a big sessionstore.js file looks like when you open it in a text editor?
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Post by trolly »

Yep, i have. A good editor, a few search and replace runs and you have one entry per line.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
QonoS
Posts: 234
Joined: February 11th, 2003, 8:09 pm

Post by QonoS »

We're getting somewhere, thanks. Are you willing to share the search/replace strings (or help me in figuring out what to look for)? Thanks.
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Post by trolly »

Do you have an editor which is able to insert new lines during search/replace? I know only one or two which can.
I use this one: http://www.codeproject.com/KB/recipes/notepadre.aspx

One easy step is inserting a new line before "{url".

But i have to go to bed now. It is past midnight here and i have to get up early.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
QonoS
Posts: 234
Joined: February 11th, 2003, 8:09 pm

Post by QonoS »

No rush. Thanks for the reply, and I hope you get some sleep.

Using, of all things, M$ Word (!) (because I know the codes for special characters, like newlines, in Word) I've put newlines in front of "{entries:", "children:" and "url:". I've color-coded those three strings as well, just to make the visuals easier.

So how about this? I guess the info I'm mostly interested in extracting from the file is the code that means:

1) A New Window Starts Here.
2) A New Tab Starts Here.
3) The Main URL Of The New Tab Is:

Based on that, is there anything I should be looking for?
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Post by trolly »

{windows:[
{tabs:[
{entries:[
{url:

And the last url in the list is the last one visited. I think you can ignore the children entry on a tab.
I'm not completely sure about the children but they seem to be the entries in a frameset.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
QonoS
Posts: 234
Joined: February 11th, 2003, 8:09 pm

Post by QonoS »

That's great, thanks.

There's only one "{windows:" string in the entire document. I'm guessing this is normal; just sort of a header. Sort of.

"{tabs:" seems to indicate the start of a new window, and then "{entries:" separates tabs.

Does that seem right?

The "children:" entries do appear irrelevant to what I want to do. I think it's useful to highlight and break them out, because it makes deleting unnecessary info easier. My $0.02 for anybody else who gets into a similar pickle.

Thanks for all the help.
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Post by trolly »

If you had several windows open you get multiple "windows" entries.
"tabs" defines a tab and the "url" entries describe the complete stored history of that tab.

BTW: This extension (NightlyTesterTools adds a "Restore from last session" entry to the history menu. I forgot about it. :oops:
If you have it just create a new session and restore the tabs using that menu item.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
QonoS
Posts: 234
Joined: February 11th, 2003, 8:09 pm

Post by QonoS »

Thanks for all the help trolly. Much appreciated.
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Post by trolly »

:-)
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
ZeePrime
Guest

Try this

Post by ZeePrime »

QonoS,

Here's a "quick-and-dirty" approach to extracting info from your sessionstore.js file. Just replace the line "<PUT CONTENTS OF sessionstore.js HERE!>" with the contents of your sessionstore.js file and open this puppy in mozilla as a standard html file.

-Z'

PS: I'm *way* too lazy to make this into an extension, but if anyone else wants to, you have my full blessing. :-D

-- cut --

<html><head>
<style type="text/css">
a.selected, li.selectedtab { color: blue; font-weight: bold; }
li.closedtab { color: red; text-decoration: line-through; }
</style>
</head><body>
<ul id="windows">
<script type="text/javascript">
function dowindow(wind,wname,wclass) {
document.write("<li class=\"" + wclass + "\">");
document.write("<b>" + wname + "</b>");
document.write("<ol class=\"tabs\">");
var sel = wind["selected"];
var tabs = wind["tabs"];
for (var j = 0; j < tabs.length; j++) {
var tabclass = "tab"
if (j + 1 == sel) tabclass = "selectedtab"
dotab(tabs[j],"Tab #" + (j+1),tabclass);
}
var tablen = tabs.length;
tabs = wind["_closedTabs"];
for (var j = 0; j < tabs.length; j++) {
dotab(tabs[j]["state"],"Tab #" + (tablen + j + 1),"closedtab");
}
document.write("</ol>");
document.write("</li>");
}
function dotab(tab,tname,tclass) {
document.write("<li class=\"" + tclass + "\">");
document.write("<b>" + tname + "</b>");
document.write("<ul class=\"urls\">");
var sel = tab["index"];
var urls = tab["entries"];
for (var j = 0; j < urls.length; j++) {
var urlclass = "url"
if (j + 1 == sel) urlclass = "selectedurl"
dourl(urls[j],urlclass);
}
document.write("</ul>");
document.write("</li>");
}
function dourl(url,uclass) {
document.write("<li class=\"" + uclass + "\">");
var uname = url["title"];
if (!(uname) || uname == "") uname = url["url"];
document.write("<a href=\"" + url["url"] + "\">" + uname + "</a>");
document.write("</li>");
}
var data = <PUT CONTENTS OF sessionstore.js HERE!>;
var windows = data["windows"];
for (var i = 0; i < windows.length; i++) {
dowindow(windows[i],"Window #" + (i+1),"window");
}
</script>
</ul>
</body></html>
0rsted
Guest

simple parser

Post by 0rsted »

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
QonoS
Posts: 234
Joined: February 11th, 2003, 8:09 pm

Re: Extracting open URLs from sessionstore.js?

Post by QonoS »

I quit watching this topic a while ago and was going through back email... so, belatedly, huge thanks to ZeePrime and Orsted! Much appreciated.
Locked