disconnect port explicitly in FF

This commit is contained in:
tophf 2020-10-11 14:37:55 +03:00
parent 4d1110986c
commit 740a16a563
2 changed files with 6 additions and 3 deletions

View File

@ -15,6 +15,8 @@ if (typeof self.oldCode !== 'string') {
if (msg.code != null) self.oldCode = msg.code; 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});
}); });
} }

View File

@ -398,9 +398,10 @@
} }
}); });
port.onDisconnect.addListener(() => { port.onDisconnect.addListener(() => {
browser.tabs.get(tabId) chrome.tabs.get(tabId, tab =>
.then(tab => tab.url === initialUrl && location.reload()) !chrome.runtime.lastError && tab.url === initialUrl
.catch(closeCurrentTab); ? location.reload()
: closeCurrentTab());
}); });
return (opts = {}) => new Promise((resolve, reject) => { return (opts = {}) => new Promise((resolve, reject) => {
const id = performance.now(); const id = performance.now();