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:
LINK1
and this:
LINK2
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:
- I click on the browserAction and its docked popup opens.
- The popup shows a simple menu with a handful of items.
- 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} - 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.