Bug 1411351 - Fix Console error "WeakMap key must be an object..." that happens when opening a new tab, r?aswan draft
authorBob Silverberg <bsilverberg@mozilla.com>
Thu, 26 Oct 2017 14:31:43 -0400
changeset 687027 8a12490cbe2d250925a2a9bffdf38cd0fcd6d174
parent 686074 dfb54d604158f5605fb07f41751e36bfef641a2f
child 737547 53a94875508cec21410a80196883aac32c4d954a
push id86383
push userbmo:bob.silverberg@gmail.com
push dateThu, 26 Oct 2017 18:32:08 +0000
reviewersaswan
bugs1411351
milestone58.0a1
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
@@ -289,20 +289,22 @@ this.tabs = class extends ExtensionAPI {
               }
 
               fireForTab(tabManager.wrapTab(tabElem), changed);
             }
           };
 
           let isArticleChangeListener = (eventName, event) => {
             let {gBrowser} = event.target.ownerGlobal;
-            let tab = tabManager.getWrapper(
-              gBrowser.getTabForBrowser(event.target));
+            let nativeTab = gBrowser.getTabForBrowser(event.target);
 
-            fireForTab(tab, {isArticle: event.data.isArticle});
+            if (nativeTab) {
+              let tab = tabManager.getWrapper(nativeTab);
+              fireForTab(tab, {isArticle: event.data.isArticle});
+            }
           };
 
           windowTracker.addListener("status", statusListener);
           windowTracker.addListener("TabAttrModified", listener);
           windowTracker.addListener("TabPinned", listener);
           windowTracker.addListener("TabUnpinned", listener);
           windowTracker.addListener("TabBrowserInserted", listener);