Console error "WeakMap key must be an object, got undefined" from isArticleChangeListener

RESOLVED FIXED in Firefox 58

Status

defect
P2
normal
RESOLVED FIXED
2 years ago
Last year

People

(Reporter: aswan, Assigned: bsilverberg)

Tracking

56 Branch
mozilla58
Points:
---
Bug Flags:
qe-verify -

Firefox Tracking Flags

(firefox58 fixed)

Details

(Whiteboard: [tabs])

Attachments

(1 attachment)

I'm seeing this error in the browser console, it appears to happen every time a new tab is created:

WeakMap key must be an object, got undefined  ext-browser.js:271
setId chrome://browser/content/ext-browser.js:271:5
getId chrome://browser/content/ext-browser.js:251:5
wrapTab chrome://browser/content/ext-browser.js:926:47
TabManagerBase/this._tabs< chrome://extensions/content/ext-tabs-base.js:1637:44
get resource://gre/modules/ExtensionUtils.jsm:87:15
getWrapper chrome://extensions/content/ext-tabs-base.js:1708:12
isArticleChangeListener chrome://browser/content/ext-tabs.js:297:23
emit resource://gre/modules/ExtensionUtils.jsm:222:40
receiveMessage
Flags: needinfo?(bob.silverberg)
Here's what I've discovered:

When isArticleChangeListener [1] fires, it receives a browser object in event.target which is meant to be the browser object for the tab in question. It then calls gBrowser.getTabForBrowser [2] to retrieve the corresponding nativeTab object. When getTabForBrowser goes to retrieve the tab from the this._tabForBrowser map, it does not find a key for this browser, so it returns undefined. It is this undefined value that is passed into tabManager.getWrapper [3] and eventually shows up as an error in setId [4].

Via debugging I have observed that the code in addTab in tab browser.xml [5] which adds a record for a new browser to the this._tabForBrowser map does fire before isArticleChangeListener fires, but still, when isArticleChangeListener fires, the record for the browser is not found in the map. In an effort to see whether the browser added at [5] is different from the browser received at [1], I recorded some values that looked unique. I’m not sure if these are actually usable for this purpose, but what I found is that the browser added at [5] contains the following properties:

_contentRequestContextID : 320082437734494
_innerWindowID : 2147483661
_outerWindowID : 2147483659

whereas the browser received at [1] contains these properties:

_contentRequestContextID : 320082437734518
_innerWindowID : 2147483664
_outerWindowID : 2147483662

Does this prove they are different browser objects and explain why the browser isn’t found in this._tabForBrowser at [2]?

Note that this only happens when a new tab is opened to about:newtab. It does not happen when any other tabs are opened, including other about: tabs (based on the few that I’ve checked, anyway). It also does not happen when navigating to about:newtab - only when opening a new tab. It also does not happen if the newtab page is overridden by an extension. It only happens when opening the actual Firefox New Tab page.

One possible fix for this is to check the return value of gBrowser.getTabForBrowser at [2] and bail out of the listener if it is undefined. Based on my testing, the only time that will happen is when the Firefox New Tab page is used to open a tab, so I think that’s fine.

I’m still not sure what is actually causing this issue, though, so maybe we don’t want to apply a band-aid like that to it.

Do you have any further thoughts, Andrew?

[1] http://searchfox.org/mozilla-central/rev/1285ae3e810e2dbf2652c49ee539e3199fcfe820/browser/components/extensions/ext-tabs.js#295
[2] http://searchfox.org/mozilla-central/rev/d30462037ffea383e74c42542c820cf65b2b144e/browser/base/content/tabbrowser.xml#404
[3] http://searchfox.org/mozilla-central/rev/1285ae3e810e2dbf2652c49ee539e3199fcfe820/browser/components/extensions/ext-tabs.js#297
[4] http://searchfox.org/mozilla-central/rev/d30462037ffea383e74c42542c820cf65b2b144e/browser/components/extensions/ext-browser.js#271
[5] http://searchfox.org/mozilla-central/rev/d30462037ffea383e74c42542c820cf65b2b144e/browser/base/content/tabbrowser.xml#2771
Assignee: nobody → bob.silverberg
Flags: needinfo?(bob.silverberg) → needinfo?(aswan)
Priority: -- → P2
Whiteboard: [tabs]
progress on this happened on irc
Flags: needinfo?(aswan)
Comment on attachment 8922448 [details]
Bug 1411351 - Fix Console error "WeakMap key must be an object..." that happens when opening a new tab,

https://reviewboard.mozilla.org/r/193512/#review198748
Attachment #8922448 - Flags: review?(aswan) → review+
Pushed by bsilverberg@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/88a41df87dac
Fix Console error "WeakMap key must be an object..." that happens when opening a new tab, r=aswan
https://hg.mozilla.org/mozilla-central/rev/88a41df87dac
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla58
Is manual testing required on this bug? If yes, please provide some STR and the proper extension(if required) or set the “qe-verify -“ flag.

Thanks!
Flags: needinfo?(bob.silverberg)
Flags: needinfo?(bob.silverberg) → qe-verify-
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.