我尝试使用chrome.tabs.get
检测选项卡是否与tabid相对应:
chrome.tabs.get tabid, (tab) ->
if tab?
chrome.tabs.update tabid, selected: yes
# window.close()
else
url = q('#choose').querySelector('.url').innerText
options =
url: url
active: yes
chrome.tabs.create options
# window.close()
代码可以正常运行,但它会出现如下错误:
tabs.get: No tab with id: 107.
at gotoTab (chrome-extension://lldkaekdbdcgilnmbheemjooggcnhopl/lib/find.js:150:22)
很奇怪我可以通过搜索标签和书签以及历史来获取标签,但标签不存在。有没有更好的方法来检测tabid的存在?