From 740a16a5637e53248f25ea4b013a74614a2961e4 Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 11 Oct 2020 14:37:55 +0300 Subject: [PATCH] disconnect port explicitly in FF --- content/install-hook-usercss.js | 2 ++ install-usercss/install-usercss.js | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/content/install-hook-usercss.js b/content/install-hook-usercss.js index 944c235b..6e8be595 100644 --- a/content/install-hook-usercss.js +++ b/content/install-hook-usercss.js @@ -15,6 +15,8 @@ if (typeof self.oldCode !== 'string') { if (msg.code != null) self.oldCode = msg.code; }); }); + // FF keeps content scripts connected on navigation https://github.com/openstyles/stylus/issues/864 + addEventListener('pagehide', () => port.disconnect(), {once: true}); }); } diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js index c074bf16..a72b8359 100644 --- a/install-usercss/install-usercss.js +++ b/install-usercss/install-usercss.js @@ -398,9 +398,10 @@ } }); port.onDisconnect.addListener(() => { - browser.tabs.get(tabId) - .then(tab => tab.url === initialUrl && location.reload()) - .catch(closeCurrentTab); + chrome.tabs.get(tabId, tab => + !chrome.runtime.lastError && tab.url === initialUrl + ? location.reload() + : closeCurrentTab()); }); return (opts = {}) => new Promise((resolve, reject) => { const id = performance.now();