From a0fc147015840d33069400ab838d7f3a74eaae96 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 7 Dec 2020 23:08:07 +0300 Subject: [PATCH] fix temporal dead zone in apply.js --- content/apply.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/content/apply.js b/content/apply.js index f21fca1e..b4905b38 100644 --- a/content/apply.js +++ b/content/apply.js @@ -16,12 +16,21 @@ self.INJECTED !== 1 && (() => { compare: (a, b) => a.id - b.id, onUpdate: onInjectorUpdate, }); - const initializing = init(); + + // save it now because chrome.runtime will be unavailable in the orphaned script + const orphanEventId = chrome.runtime.id; + let isOrphaned; + // firefox doesn't orphanize content scripts so the old elements stay + if (!chrome.app) styleInjector.clearOrphans(); + /** @type chrome.runtime.Port */ let port; let lazyBadge = IS_FRAME; let parentDomain; + // Declare all vars before init() or it'll throw due to "temporal dead zone" of const/let + const initializing = init(); + // the popup needs a check as it's not a tab but can be opened in a tab manually for whatever reason if (!IS_TAB) { chrome.tabs.getCurrent(tab => { @@ -30,12 +39,6 @@ self.INJECTED !== 1 && (() => { }); } - // save it now because chrome.runtime will be unavailable in the orphaned script - const orphanEventId = chrome.runtime.id; - let isOrphaned; - // firefox doesn't orphanize content scripts so the old elements stay - if (!chrome.app) styleInjector.clearOrphans(); - msg.onTab(applyOnMessage); if (!chrome.tabs) {