"Cannot access dead object" error when reading an user object set by popup within the background page object

Hello everyone
just joined the forum and this is my first message.

When migrating an MV2 extension from Chrome to Firefox
I was faced with a strange error message that had never appeared before: “Can’t access dead object”

I did a web search and found this:
and this:
but unfortunately the articles have not been of much help to me.

In fact in my case I do not store DOM nodes of documents which are subsequently destroyed.

The operations I do are the following:

  1. I click on the browserAction and its docked popup opens.
  2. The popup shows a simple menu with a handful of items.
  3. When I click on one of these items a tab is opened (with a different html + js file).
    Before opening the tab, the popup retrieves the background page with bckgrnd = browser.extension.getBackgroundPage()
    and adds a very simple object inside it
    bckgrnd.myObj = {‘t’: 3, ‘f’: 0}
  4. Now from the other side, (the newly opened tab) I do the complementary thing that is to retrieve the background page
    with bckgrnd = browser.extension.getBackgroundPage()
    and read the myObj object which should be inside the background page.
    Unfortunately I get the above error: “Can’t access dead object

After several attempts (including replacing the synchronous browser.extension.getBackgroundPage() with the asynchronous browser.runtime.getBackgroundPage())
I realized that from the popup page i couldn’t do what i did.
I cannot do this:
bckgrnd.myObj = {‘t’: 3, ‘f’: 0}
and I cannot do this:
bckgrnd.myObj = [3, 0, ‘a’]

but I can do:
bckgrnd.t = 3, bckgrnd.f = 0;
and I can also do
bckgrnd.myObj = JSON.stringify({‘t’: 3, ‘f’: 0})

If I try to add that object in extension page I don’t have the same issue.
It only happens in the browserAction popup.

I didn’t face this kind of problem with Chromium-based browsers.
My question is simple: WHY?
Is it deliberate or is it just a bug?

Thank you in advance.

I can not answer the why, but I can point out that the safe way to do this is to use messaging (runtime.sendMessage) since that will use a cloning algorithm on the message, thus decoupling it from its source.

Yes, I guess the exchange of messages is a more elegant solution, but for my case it is less practical.
The tab I’m going to create is not yet ready to receive messages sent by the popup and therefore the message would be lost.
The alternative could be to add a querystring made by these parameters (?t=3&f= 0) to the url when I create the tab.
I don’t really like the idea of making this new url visible to the user
because he might want to play and mess with it.

Or using two steps for messaging, sending a message from popup to background, and then having another message from background to content script (or the other way around). Alternatively you could use executeScript to inject the information into the relevant tab directly and trigger your content script logic from that.

Thank you.
I solved with: bckgrnd.myObj = JSON.parse(JSON.stringify({‘t’: 3, ‘f’: 0}))
It’s surely a bug