0

I'm trying to write a Firefox extension and came across a weird behavior that I found no information on:

When calling browser.windows.get() (or some other browser.windows functions), the promise will never resolve but also the function won't throw any error. If I await the promise, the program is stuck and following lines won't be executed.

So I did console.log(browser.windows) to check if the function exists at all and got this:

Object { onCreated: Getter & Setter, onRemoved: Getter & Setter, onFocusChanged: Getter & Setter, get: Getter & Setter, getLastFocused: Getter & Setter, getAll: Getter & Setter, create: Getter & Setter, update: Getter & Setter, remove: Getter & Setter, WINDOW_ID_CURRENT: Getter & Setter, … }
​
CreateType: TypeError: can't access dead object
​
GetInfo: TypeError: can't access dead object
​
WINDOW_ID_CURRENT: TypeError: can't access dead object
​
WINDOW_ID_NONE: TypeError: can't access dead object
​
Window: TypeError: can't access dead object
​
WindowState: Object { NORMAL: "normal", MINIMIZED: "minimized", MAXIMIZED: "maximized", … }
​
WindowType: TypeError: can't access dead object
​
create: TypeError: can't access dead object
​
get: TypeError: can't access dead object // unfolded
​​
  columnNumber: 0
​​
  fileName: ""
​​
  lineNumber: 0
​​
  message: "can't access dead object"
​​
  stack: ""
​​
  <prototype>: TypeError.prototype { stack: "", … }
​
getAll: TypeError: can't access dead object
​
getCurrent: function () // unfolded
​​
  length: 1
​​
  name: ""
​​
<prototype>: function ()
​
getLastFocused: TypeError: can't access dead object
​
onCreated: TypeError: can't access dead object
​
onFocusChanged: TypeError: can't access dead object
​
onRemoved: TypeError: can't access dead object
​
remove: TypeError: can't access dead object
​
update: TypeError: can't access dead object // unfolded
​​
  columnNumber: 0
​​
  fileName: ""
​​
  lineNumber: 0
​​
  message: "can't access dead object"
​​
  stack: ""
​​
  <prototype>: TypeError.prototype { stack: "", … }
​​​
<get CreateType()>: function ()
​
<set CreateType()>: function ()
​
<get GetInfo()>: function ()
​
<set GetInfo()>: function ()
​
<get WINDOW_ID_CURRENT()>: function ()
​
<set WINDOW_ID_CURRENT()>: function ()
​
<get WINDOW_ID_NONE()>: function ()
​
<set WINDOW_ID_NONE()>: function ()
​
<get Window()>: function ()
​
<set Window()>: function ()
​
<get WindowType()>: function ()
​
<set WindowType()>: function ()
​
<get create()>: function ()
​
<set create()>: function ()
​
<get get()>: function ()
​​
length: 0
​​
name: ""
​​
<prototype>: function ()
​
<set get()>: function ()
​​
length: 1
​​
name: ""
​​
<prototype>: function ()
​
<get getAll()>: function ()
​
<set getAll()>: function ()
​
<get getLastFocused()>: function ()
​
<set getLastFocused()>: function ()
​
<get onCreated()>: function ()
​
<set onCreated()>: function ()
​
<get onFocusChanged()>: function ()
​
<set onFocusChanged()>: function ()
​
<get onRemoved()>: function ()
​
<set onRemoved()>: function ()
​
<get remove()>: function ()
​
<set remove()>: function ()
​
<get update()>: function ()
​​
length: 0
​​
name: ""
​​
<prototype>: function ()
​
<set update()>: function ()
​​
length: 1
​​
name: ""
​​
<prototype>: function ()
​
<prototype>: Object { … }

I marked some functions that I have unfolded in the console. So browser.windows.get() exists, but it says "can't access dead object". A couple more say the same, while others are just empty somehow (with only length and an empty string as name).

The official docs on browser.windows don't mention this behavior.

The only explanation I came up with is that some relevant API permission is missing, but I could't find any permission related to browser.windows.

I'm testing with Firefox 94 on desktop (Ubuntu).

Does anyone know what this means and how to fix it?

Fred
  • 1,103
  • 2
  • 14
  • 35
  • 1
    Hi @Fred , did you manage to solve this issue? I am getting similar `can't access dead object` issues while creating an extension with react, it works pretty well on Chrome :/ – LoXatoR Nov 21 '21 at 14:44
  • 1
    Nope. Unfortunately not. I figured out that this has something to do with memory leak prevention in FF but as I'm not actively creating this object, I have no idea, why it is being wiped or how to avoid it :-P – Fred Nov 23 '21 at 12:58
  • 1
    Yeah, I have been searching through the internet as well to no avail. All the threads are super outdated and Mozilla says to check for dead object using `Components.utils` but the links to those pages are dead. I don't know if its any help to you but in my case, I am trying to access the redux store in the BackgroundProcessor page, and that is killed by Firefox when the extension closes, hence running into this error. – LoXatoR Nov 23 '21 at 13:48
  • 1
    The Mozilla docs are catastrophic, tons of outdated info and dead links. It also says "use Component.utils to check if the object is dead before accessing it" but it doesn't say how to deal with the situation or even avoid it. I tried to resort to the Chrome docs because extensions are 80 % the same, but Chrome doesn't have this particular problem. – Fred Nov 23 '21 at 14:03
  • 1
    Couldn't agree with you more, it's the way Firefox is handling memory, I guess Chrome gives the devs bit of a lee-way but FF doesn't. Maybe for your case you are trying to call the `window` object somewhere but FF has killed. Or `setTimeout` functions. Sorry couldn't be of much help. – LoXatoR Nov 23 '21 at 15:13
  • 1
    Hi again, I had some luck on my end by trying to dereference object as `JSON.parse(JSON.stringify(object))`, errors have minimized. You could try the same on your end. Similar method described here - https://stackoverflow.com/questions/52618377/firefox-web-extension-cant-access-dead-object-error Hope it helps – LoXatoR Nov 25 '21 at 20:04
  • Thanks a lot for sharing! I'll try :-) – Fred Nov 25 '21 at 21:28
  • Curious if it worked for you @Fred – LoXatoR Nov 29 '21 at 09:31
  • 1
    I put this project on hold after not finding a solution to the issue. I'll get back to you when I have tried but don't expect it to happen soon... – Fred Nov 29 '21 at 15:40
  • 1
    No worries, was just curious. Thanks for the update! – LoXatoR Nov 29 '21 at 15:52

0 Answers0