Use case: My extension fails to find the window I want so it opens one and captures the tab id (400, for example). So now I am working along fine with that id but then the user closes the tab. Meanwhile my Chrome extension still has that id and has no way of knowing to open a new window.
What’s the best way to validate the id, determine that it’s invalid so I can initiate my search/open again?
If you add a listener to the
onRemovedevent of the Tabs API, (viachrome.tabs.onRemoved.addListener), you’ll be able to execute code in response to a tab closing. The event will include the ID of the tab that’s just been closed, which should allow you to keep your extension in sync with the user’s current layout.