From b5d5970a854fd7f96ca42842d0096d2ee8e6cda8 Mon Sep 17 00:00:00 2001 From: def00111 Date: Tue, 6 Jul 2021 18:00:39 +0200 Subject: [PATCH] Fix sendRemoveListener on closed conduit when unloading a page (#312) * Update simple-translate.js * Update background.js * Update manifest.json * Delete background.js * Delete manifest.json * Delete simple-translate.js * Update index.js --- src/content/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/content/index.js b/src/content/index.js index dab2449..93d2171 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -9,6 +9,7 @@ const init = async () => { await initSettings(); document.addEventListener("mouseup", handleMouseUp); document.addEventListener("keydown", handleKeyDown); + window.addEventListener("unload", onUnload, { once: true }); browser.storage.onChanged.addListener(handleSettingsChange); browser.runtime.onMessage.addListener(handleMessage); overWriteLogLevel(); @@ -132,6 +133,10 @@ const handleKeyDown = e => { } }; +const onUnload = () => { + browser.storage.onChanged.removeListener(handleSettingsChange); +}; + let isEnabled = true; const handleMessage = async request => { const empty = new Promise(resolve => {