Skip to content

Commit cecf0ba

Browse files
committed
when a tab is closed, remove it from open spots
1 parent 23d04b2 commit cecf0ba

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/entrypoints/background.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { CommentEvent, CommentSpot } from '@/lib/enhancer'
22
import { type DraftStats, statsFor } from '@/lib/enhancers/draft-stats'
33
import { logger } from '@/lib/logger'
44
import type { GetTableRowsResponse, ToBackgroundMessage } from '@/lib/messages'
5-
65
import {
76
CLOSE_MESSAGE_PORT,
87
isContentToBackgroundMessage,
@@ -115,4 +114,16 @@ export default defineBackground(() => {
115114
return handlePopupMessage(message, sender, sendResponse)
116115
}
117116
})
117+
118+
browser.tabs.onRemoved.addListener((tabId: number) => {
119+
logger.debug('tab removed', { tabId })
120+
121+
// Clean up openSpots entries for the closed tab
122+
for (const [key, value] of openSpots) {
123+
if (tabId === value.tab.tabId) {
124+
openSpots.delete(key)
125+
logger.debug('closed tab which contained spot', value.spot.unique_key)
126+
}
127+
}
128+
})
118129
})

0 commit comments

Comments
 (0)