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;
});
});
// 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(() => {
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();