browser.tabs.onRemoved.addListener not functioning correctly

I'm creating a safari extension where if a tab/window is closed, I need it to do some background cleaning, for example removing the local storage data.

I tried the following lines in my background.js:

browser.tabs.onRemoved.addListener((tabId, removeInfo) => {
    console.log("tab closed");
});

browser.windows.onRemoved.addListener(function(windowid) {
    console.log("window closed")
})

windows.onRemoved seems to work fine, but tabs.onRemoved seems to be working exactly like windows.onRemoved. I've tested it multiple times and every time without any hesitation, I don't get any "tab closed" in my console logs. But when I close the window, I get both messages above. Is this a bug? Is there something I'm missing?

I'm using Safari v16.3

ps. I've tried all permutations with the "function(){}" syntax and "() => {}". Same results all around.

UPDATE: Further Investigation

After some investigation I've come to understand that this issue only happens for tabs inside of safari's "Tab Groups" feature. When I tested this not inside of a TabGroup, it successfully worked as expected. If anyone in the Safari Extension Team can create a ticket for this and address it, I would really appreciate it. 🙏

Can you file some feedback about this on https://feedbackassistant.apple.com? Ideally this would include a sample extension and steps to reproduce.

Thank you!

browser.tabs.onRemoved.addListener not functioning correctly
 
 
Q