Bug 1411351 - Fix Console error "WeakMap key must be an object..." that happens when opening a new tab, r=aswan
authorBob Silverberg <bsilverberg@mozilla.com>
Thu, 26 Oct 2017 14:31:43 -0400
changeset 388715 88a41df87dacd767dbbf392ec624917a4e3881d6
parent 388714 2ac09a374b698d7cbb4cc50bf8245305aa07a347
child 388716 55f33f1364a73afb5840b524ac1b6252ff95ae9f
push id54234
push userbsilverberg@mozilla.com
push dateFri, 27 Oct 2017 13:24:58 +0000
treeherderautoland@88a41df87dac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1411351
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1411351 - Fix Console error "WeakMap key must be an object..." that happens when opening a new tab, r=aswan When the New Tab page is opened, the browser object that is passed into the isArticleChangeListener is not a valid browser from the perspective of tabbrowser.xml, so it is not able to find it in its _tabForBrowser map. This causes undefined to be passed into tabManager.getWrapper(), which causes the error. This patch fixes this by not calling tabManager.getWrapper(), and subsequently firing the onUpdate event, if the return value from gBrowser.getTabForBrowser() is undefined. Testing shows that that is only the case when the New Tab page is opened, and that page is not, and is unlikely to be readerable any time in the foreseeable future (confirmed on IRC), so ignoring this case in the listener is acceptable. MozReview-Commit-ID: D9LQRrPmCoU
browser/components/extensions/ext-tabs.js
--- a/browser/components/extensions/ext-tabs.js
+++ b/browser/components/extensions/ext-tabs.js
@@ -287,22 +287,24 @@ this.tabs = class extends ExtensionAPI {
               if (url) {
                 changed.url = url;
               }
 
               fireForTab(tabManager.wrapTab(tabElem), changed);
             }
           };
 
-          let isArticleChangeListener = (eventName, event) => {
-            let {gBrowser} = event.target.ownerGlobal;
-            let tab = tabManager.getWrapper(
-              gBrowser.getTabForBrowser(event.target));
+          let isArticleChangeListener = (messageName, message) => {
+            let {gBrowser} = message.target.ownerGlobal;
+            let nativeTab = gBrowser.getTabForBrowser(message.target);
 
-            fireForTab(tab, {isArticle: event.data.isArticle});
+            if (nativeTab) {
+              let tab = tabManager.getWrapper(nativeTab);
+              fireForTab(tab, {isArticle: message.data.isArticle});
+            }
           };
 
           windowTracker.addListener("status", statusListener);
           windowTracker.addListener("TabAttrModified", listener);
           windowTracker.addListener("TabPinned", listener);
           windowTracker.addListener("TabUnpinned", listener);
           windowTracker.addListener("TabBrowserInserted", listener);