Closed Bug 2002643 Opened 2 months ago Closed 1 month ago

browser.sessions.setTabValue extension data lost when tab is adopted in another window

Categories

(WebExtensions :: General, defect)

Firefox 145
defect

Tracking

(firefox148 fixed)

VERIFIED FIXED
148 Branch
Tracking Status
firefox148 --- fixed

People

(Reporter: thibautguenedal, Assigned: robwu)

References

Details

(Whiteboard: [addons-jira])

Attachments

(1 file)

Steps to reproduce:

  • Store extension data on a tab using browser.sessions.setTabValue()
  • Move the tab to a different window
  • Check data using browser.sessions.getTabValue()
// permissions: ["tabs", "windows", "sessions"]
tab = await browser.tabs.create({ url: 'https://example.com' })
await browser.sessions.setTabValue(tab.id, 'key', 'value')
console.log('key', await browser.sessions.getTabValue(tab.id, 'key'))
await browser.windows.create({ tabId: tab.id })
console.log('key', await browser.sessions.getTabValue(tab.id, 'key')) 

Actual results:

All extension data (tab values) is lost after moving the tab to a new window. I confirmed this by inspecting sessionstore.json > tab.extData before and after the move.

Expected results:

This data persists on a tab through reload, navigation, moving, grouping, pinning, closing and reopening, restarting the browser, etc. so I don't understand why it gets destroyed when moving between windows.

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Product: Firefox → WebExtensions

I can confirm this issue.
Using a minimal MV2 extension, tab session data set with browser.sessions.setTabValue() is lost after detaching the tab to a new window.
Tested on Firefox 142.0.2, macOS Sequoia 15.7.1.

Status: UNCONFIRMED → NEW
Ever confirmed: true

The severity field is not set for this bug.
:robwu, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(rob)

The logic for assigning the custom state is at https://searchfox.org/firefox-main/rev/04cf27582307a9c351e991c740828d54cf786b76/browser/components/sessionstore/SessionStore.sys.mjs#4925-4938

The issue happens because adopting a tab in Firefox is implemented as creating a new tab in the new window based on the original tab, and then swapping the <browser> that holds the tab's content. Extensions do not notice the difference because we do some bookkeeping to preserve the tabId after tab adoption, in tabTracker's adopt handler (called on TabOpen/TabClose).

I believe that the issue will be resolved if we copy over the state when a tab is adopted in a new window, e.g. in SessionStore.sys.mjs's TabClose handler when adoptedBy is set, or in the callee (SessionStoreInternal.onMoveToNewWindow, provided that the caller passes the tab instead of the <browser>).

Thibaut, are you interested in contributing a patch to Firefox to fix this issue? If you are, there is a quick guide to getting started at https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html

Component: Untriaged → General
Flags: needinfo?(rob)
Summary: browser.sessions extension data lost when tab is detached → browser.sessions.setTabValue extension data lost when tab is adopted in another window

The severity field is not set for this bug.
:willdurand, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(wdurand)
Assignee: nobody → rob
Flags: needinfo?(wdurand)
Whiteboard: [addons-jira]
Pushed by rob@robwu.nl: https://github.com/mozilla-firefox/firefox/commit/782b1abb8a35 https://hg.mozilla.org/integration/autoland/rev/6e4abb939345 Preserve custom tab value when tab is adopted r=sessionstore-reviewers,sthompson
Status: NEW → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 148 Branch

Verified FIXED.
On Firefox 148 (macOS), extension data set via browser.sessions.setTabValue() is preserved after tab adoption into a new window using browser.windows.create({ tabId }).
sessions.getTabValue() returns the expected value both before and after adoption.

Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: