captnfab / FireTitle

A firefox extension allowing customisation of windows' title
25 stars 9 forks source link

Titles assigned to wrong windows after session restore #16

Closed molexx closed 6 years ago

molexx commented 6 years ago

For a clean test I created a new profile in FF Developer Edition 57.0b3 from aurora update channel.

Open three windows In each window open a page you'll recognise - I just did google searches for 'window one', 'window two' and 'window three' In each window open CrappyFireTab and set the title - I used 'win1', 'win2' and 'win3' - closing the plugin's config tab between each one otherwise pressing the toolbar button jumps to the already open one in the other window. Quit Firefox. Reopen firefox and press restore session. I've also tested by changing the settings to restore session by default. The three windows appear, with their three google searches, but their CrappyFireTitle title seems to be randomly assigned.

captnfab commented 6 years ago

Thanks for your report, I'll investigate.

captnfab commented 6 years ago

Ok, I found the cause of the problem. When a session is restored, the windows are restored but their Id may change. So, storing window's names / title patterns using window's id can't work. Apparently, window.sessionId is the way to go, but those look empty…

rsalmei commented 6 years ago

Hey! Thanks for the response in the mozilla review. Just came here to vote for the issue. It should have a way to accomplish this... Good luck!

Betlista commented 6 years ago

FF 57.0 forced me to switch from FireTitle to Crappy and after FF restart (I have option "Show your windows and tabs from last time") all titles (except one) are gone :-(

captnfab commented 6 years ago

Yes. Windows naming on restore is broken. Any help is welcome.

Betlista commented 6 years ago

@captnfab Can you point me directly to part, in which it is storing/loading titles?

captnfab commented 6 years ago

Sure. The problem is actually pretty simple.

Loadding occurs here: https://github.com/captnfab/FireTitle/blob/106507e1e8bf9cd2755872ba4882018c5d0fc98d/firetitle/background.js#L8 window's Pattern/name are saved in the local storage as win+windowId+_name/pattern. Saving part occurs here: https://github.com/captnfab/FireTitle/blob/106507e1e8bf9cd2755872ba4882018c5d0fc98d/firetitle/background.js#L48

Unfortunately, window's ids change upon restore. This means storing parameters that way can't work. When I tried, the window.sessionId was a blank field, so it was unreliable too.

Hence, the problem is I don't know how to keep track of a window through session restoration…

captnfab commented 6 years ago

I think that the local storage is the wrong way to go. Using sessions seems a much clearer approach: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/sessions

captnfab commented 6 years ago

Let me try to do something...

Betlista commented 6 years ago

I do not see the problem with local storage... The problem is a unique identifier. I see few candidates in https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/Tab id or sessionId, can you try tab.sessionId instead of window.sessionId ? I know that you are doing it on window level, maybe you can do something like save id/sessionId of a first tab in every window...

captnfab commented 6 years ago

I've got it working. I'm doing some cleaning since I'm not really proud of the state of the code. I'm also polishing the UI. I'll try to push the new version today and upload it to mozilla addons website for review.

eceprof commented 6 years ago

Captnfab, you are fabulous. I just "upgraded" to Firefox Quantum and to my dismay lost the ability to use FireTitle, felt saved by Crappy FireTitle and then discovered the session restore problem!!! Imagine my relief when I opened this page and discovered at the end of it that you have found a solution the very day I looked for one. Thank you so much for being a lifesaver. FireTitle is second only to session restore to being my most needed and loved FireFox extension/capability.

captnfab commented 6 years ago

I've uploaded the new version to addons.mozilla.org and it is now pending review.

captnfab commented 6 years ago

@eceprof hehe, thanks! The addons.mozilla.org version has been approved. Please tell me if it works well for you :)

Betlista commented 6 years ago

I'm also going to test immediately ;-)

Betlista commented 6 years ago

Tested with 24 windows and 236 tabs and worked as expected, thanks for fix!