Bug 1411351 - Fix Console error "WeakMap key must be an object..." that happens when opening a new tab,
59 bytes, text/x-review-board-request
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
Here's what I've discovered: When isArticleChangeListener  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  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  and eventually shows up as an error in setId . Via debugging I have observed that the code in addTab in tab browser.xml  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  is different from the browser received at , 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  contains the following properties: _contentRequestContextID : 320082437734494 _innerWindowID : 2147483661 _outerWindowID : 2147483659 whereas the browser received at  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 ? 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  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?  http://searchfox.org/mozilla-central/rev/1285ae3e810e2dbf2652c49ee539e3199fcfe820/browser/components/extensions/ext-tabs.js#295  http://searchfox.org/mozilla-central/rev/d30462037ffea383e74c42542c820cf65b2b144e/browser/base/content/tabbrowser.xml#404  http://searchfox.org/mozilla-central/rev/1285ae3e810e2dbf2652c49ee539e3199fcfe820/browser/components/extensions/ext-tabs.js#297  http://searchfox.org/mozilla-central/rev/d30462037ffea383e74c42542c820cf65b2b144e/browser/components/extensions/ext-browser.js#271  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
progress on this happened on irc
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 firstname.lastname@example.org: 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
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) → qe-verify-
You need to log in before you can comment on or make changes to this bug.