thePaulV / Most-Recent-Tab

Firefox addon that adds a keyboard shortcut to switch back to your most recently selected tab. Useful to alternate between two tabs and to easily go back to your last tab if you switch to another briefly.
https://addons.mozilla.org/en-US/firefox/addon/most-recent-tab/
Mozilla Public License 2.0
12 stars 4 forks source link

Store the history on the session so that it survives restarts etc #11

Open thePaulV opened 3 years ago

thePaulV commented 3 years ago

Description

Currently the history is stored in addon's memory, and reset every time Firefox is relaunched. With the sessions API, this data could be stored against the window or tabs directly and preserved across sessions.

Steps to Reproduce

  1. Do some browsing
  2. Close Firefox
  3. Restart Firefox
  4. Use the shortcut

Expected behavior: [What you expected to happen]

  1. The most recent tab from the last session is opened

Actual behavior: [What actually happens]

  1. Nothing

Other Information and Versions

Approach 1: Save a queue to the Window

Instead of having a Map from windowID -> queue, store a queue directly on the window session.

Pros - Very similar to how the addon works already, easy to migrate to. Notes - Objects saved to the session are stringified, so we'd likely be serializing JSON. This could be slow with lots of tabs. We could cap the history length to mitigate this.

Approach 2: Save something on each tab

Instead of having a queue, store a reference to the previous tab, or a sequence number, on each tab.

Pros - No more maintaining a separate structure of tabs, pushing things down to the tabs themselves. Cons - Different approach, would require more rework. Sequence number approach would require O(number of tabs in window) operations. Reference to previous tab would be quick but need a bit more bookkeeping.