screenglow
screenglow

Reputation: 1886

How can I validate a tab id in my Chrome Extension?

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?

Upvotes: 0

Views: 110

Answers (1)

Mike West
Mike West

Reputation: 5141

If you add a listener to the onRemoved event of the Tabs API, (via chrome.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.

Upvotes: 1

Related Questions