简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM