[英]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). 用例:我的扩展程序找不到我想要的窗口,因此它打开了一个窗口并捕获了选项卡ID(例如400)。 So now I am working along fine with that id but then the user closes the tab.
因此,现在我可以使用该ID正常工作,但是用户可以关闭该标签。 Meanwhile my Chrome extension still has that id and has no way of knowing to open a new window.
同时,我的Chrome扩展程序仍然具有该ID,并且无法打开新窗口。
What's the best way to validate the id, determine that it's invalid so I can initiate my search/open again? 验证ID并确定其无效的最佳方法是什么,以便我可以再次启动搜索/打开?
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. 如果您将侦听器添加到Tabs API的
onRemoved
事件中( 通过chrome.tabs.onRemoved.addListener
),则可以执行代码以响应选项卡关闭。 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. 该事件将包含刚刚关闭的标签的ID,这应允许您使扩展名与用户当前的布局保持同步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.