Skip to content

fix: restore recently closed tabs with navigation history#2373

Open
Draly wants to merge 1 commit into
mbnuqw:v5from
Draly:fix/restore-closed-tabs-with-history
Open

fix: restore recently closed tabs with navigation history#2373
Draly wants to merge 1 commit into
mbnuqw:v5from
Draly:fix/restore-closed-tabs-with-history

Conversation

@Draly
Copy link
Copy Markdown

@Draly Draly commented Mar 14, 2026

Summary

  • Use browser.sessions.restore() instead of Tabs.open() when reopening tabs from the "Recently closed tabs" panel (trash icon), so the restored tab preserves its full navigation history (back/forward buttons work).
  • Falls back to the previous Tabs.open() behavior when the tab is no longer available in browser sessions (e.g. older than 25 entries).
  • Handles branch restoration: tries session restore for each tab individually, with fallback for tabs not found in sessions.

Problem

Currently, clicking a tab in the "Recently closed tabs" sub-panel creates a brand new tab via browser.tabs.create({ url }). This means the restored tab loses its entire navigation history -- the back button doesn't work, unlike Firefox's native "Recently closed tabs" (History menu) which uses browser.sessions.restore().

Solution

Modified the openTabs() function in sub-panel.closed-tabs.vue to:

  1. First attempt to find the closed tab in browser.sessions.getRecentlyClosed()
  2. If found, restore it via browser.sessions.restore(sessionId) (preserves history)
  3. If not found, fall back to the existing Tabs.open() behavior

Limitations

  • browser.sessions.getRecentlyClosed() is limited to ~25 entries by default (browser.sessionstore.max_tabs_undo). Tabs beyond this limit will use the fallback.
  • browser.sessions.restore() restores the tab at its original position; Sidebery's tab event handlers will then integrate it into the tree.

Test plan

  • Open a tab, navigate through several pages (building history), close the tab
  • Open the "Recently closed tabs" panel (trash icon) and click the closed tab
  • Verify the back button works and navigation history is preserved
  • Test with branch restoration (close a parent tab with children, restore via branch button)
  • Test fallback: close many tabs (>25) and try restoring an old one -- should still open via URL

Use browser.sessions.restore instead of Tabs.open when reopening tabs from the Recently closed tabs panel, so the restored tab preserves its full navigation history. Falls back to Tabs.open when the tab is no longer available in browser sessions.
@mbnuqw
Copy link
Copy Markdown
Owner

mbnuqw commented Mar 21, 2026

Thanks. Currently there are some issues:

  • Container is not preserved:

    • Open https://example.com/ in default container
    • Open https://example.com/ in another container
    • Close the tab in another container
    • Close the tab in default container
    • Open RCT sub-panel and restore containered tab
    • Restored tab is wrong (different container, history)
  • Restoring branch of tabs leads to multiple active tabs:

    • Open https://example.com/
    • Open child tab https://www.iana.org/help/example-domains ("Learn more" link)
    • Close the branch (right-click on parent tab's close button)
    • Open RCT sub-panel and restore the branch
    • Both tabs marked as active

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants