如何检测给定tabid的选项卡是否存在?

时间:2013-07-15 13:57:37

标签: javascript google-chrome-extension

我尝试使用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的存在?

0 个答案:

没有答案