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();