Skip to content

Commit

Permalink
fix: prevent premature port disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusmb committed Oct 13, 2023
1 parent 5d19e5e commit a4ee0b8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions static/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit a4ee0b8

Please sign in to comment.