简体   繁体   English

如何验证Chrome扩展程序中的标签页ID?

[英]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.

相关问题 如何获取以前在Chrome扩展程序中查询的已知标签ID的更改过的网址? - How can I get the changed url of a known tab id queried before in Chrome Extension? 移至其他标签页后,如何停止我的Chrome扩展程序? - How can I get my Chrome extension to stop when i move to another tab? 如何让jQuery在我的Google chrome扩展程序创建的标签中工作? - How can i get jQuery working in a tab created by my google chrome extension? 当标签重载(Chrome扩展名)时如何运行此脚本? - How can I run this script when the tab reloads (chrome extension)? 我怎样才能打开带有 chrome 扩展的新标签页? - How can i open the new tab with chrome extension? Chrome扩展程序:无法向ID为-1的标签发送消息 - Chrome Extension: Can't send message to tab with id of -1 如何使用javascript在chrome扩展程序中创建会话? - How can I create session in my chrome extension using javascript? 如何在Chrome扩展程序中本地保存信息? - How can I save information locally in my chrome extension? 如何将PhantomJS添加到我的Chrome扩展程序中? - How Can I Add PhantomJS to My Chrome Extension? "<i>How can I fetch data in my content script?<\/i>如何在我的内容脚本中获取数据?<\/b> <i>(chrome extension)<\/i> (镀铬扩展)<\/b>" - How can I fetch data in my content script? (chrome extension)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM