Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent premature port disconnection #159

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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