diff --git a/static/background.js b/static/background.js index a5d6ba1..624bf7a 100644 --- a/static/background.js +++ b/static/background.js @@ -12,14 +12,6 @@ chrome.runtime.onConnect.addListener((port) => { if (message.type === 'ext/init') { ports.set(message.tabId, sender); - port.onDisconnect.addListener(() => { - ports.delete(message.tabId); - - if (ports.size === 0) { - chrome.tabs.onUpdated.removeListener(courier); - } - }); - return chrome.tabs.onUpdated.addListener(courier); } else if (message.type === 'ext/reload') { return chrome.runtime.reload(); @@ -30,6 +22,14 @@ chrome.runtime.onConnect.addListener((port) => { // relay messages from devtools page to `chrome.scripting` return chrome.tabs.sendMessage(message.tabId, message); }); + + port.onDisconnect.addListener((disconnected) => { + ports.delete(+disconnected.name); + + if (ports.size === 0) { + chrome.tabs.onUpdated.removeListener(courier); + } + }); }); // relay messages from `chrome.scripting` to devtools page