Closed Bug 391267 Opened 18 years ago Closed 15 years ago

On browser startup, browser window load event fires before SessionStore component is initialized

Categories

(Firefox :: Session Restore, defect)

x86
Windows XP
defect
Not set
minor

Tracking

()

VERIFIED WONTFIX

People

(Reporter: morac, Unassigned)

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6 I noticed that when I try to access SessionStore API function in functions that listen for the window load event, that SessionStore throws an exception on browser startup. The exception given is: Error: this._windows[aWindow.__SSi] has no properties I put a dump statement on the first line of SessionStore's init and onLoad functions and one the first line of my extensions window load listener and saw that on browser startup, my listener ran before both SessionStore's init and onLoad functions. Since my listener tries to use the SessionStore API it causes SessionStore to throw exception since it hasn't been initialized yet. On opening subsequent windows, SessionStore's onLoad function fires first, then my listener function and finally SessionStore's init function. So my listener works fine in this case. The SessionStore's init function should execute before the browser notifies the listeners of the window load event. Currently SessionStore's init function is called in browser.js's delayedStartup() function which is called via a SetTimeout call: http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#1122 I don't know if it's possible to call it sooner, but it would definitely help. As it is now, the init function is called after the onLoad function which seems backwards. Reproducible: Always Steps to Reproduce: Add this to extension window load event listener function: var count = Components.classes["@mozilla.org/browser/sessionstore;1"].getService(Components.interfaces.nsISessionStore).getClosedTabCount(window); Actual Results: Error: this._windows[aWindow.__SSi] has no properties Source File: file:///C:/Documents%20and%20Settings/mkraft/My%20Documents/firefox/components/nsSessionStore.js Line: 671 Expected Results: Return closed tab count
We intentionally load as late as possible in order to not unnecessarily delay startup time. Except from the fact that this is somewhat unexpected, do you have a specific use case which becomes impossible with the arrangement we've currently got? Besides: If you just initialize SessionStore for the loading window yourself, you should find it ready when you need it (initializing it again for the same window will simply be a no-op). That might already be all you need...
Well I am using the getClosedTabCount(window) function on window load, but at startup the results aren't critical so I just plop a try catch around the call to handle the first window scenario. Even with the try catch around the call, an exception will still show up in the error log. At the very least it shouldn't throw exceptions on the request or if that is to be expected update the documentation to indicate that.
That'd be bug 345898, then. Until that one's fixed, you'll then have to use the work-around from comment #1. Of course, if you step in and have a look at how to fix bug 345898, it might even get fixed anytime soon... ;-) Leaving this bug open for future consideration.
Severity: normal → minor
Status: UNCONFIRMED → NEW
Ever confirmed: true
Note to self: The only reasonable thing we could do here is call sss_onLoad ourselves if the API is used with a untracked browser window.
How about an event to notify when SessionStore is ready? I'm currently using a polling method to find out when setWindowValue works (line 238) http://www.mozdev.org/source/browse/br/multifox/src/modules/main.main.js?annotate=1.1
That might be useful since the work-around from comment #1 (calling init directly from the first loaded window) causes the maxVisibleTabs variable in the restoreHistoryPrecursor function to be set to 1 for that window. As it is now I have to do so juggling in my code to get things working since, as of Firefox 3.0, SessionStore is initialized after the first browser window loads and is destroyed before the last window unloads.
Probably fixed by bug 615394.
(In reply to comment #7) > Probably fixed by bug 615394. Sounds like it. The new events should be easy to use both for the very first window and windows added via other methods. It won't solve Michael's issue (assuming it still exists) with windows unloading, but that's ok. I'm guessing he's gone a different direction there by now anyway. I'm going to close this as WONTFIX since we aren't going to move ss initialization to sometime sooner - as was mentioned before we want to avoid delaying startup as much as possible.
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → WONTFIX
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.