【问题标题】:chrome.tabs.highlight giving error "No tab at index"chrome.tabs.highlight 给出错误“索引处没有标签”
【发布时间】:2015-05-05 21:40:23
【问题描述】:

调用chrome.tabs.highlight({'tabs': tabId}, function(){}); 时出现此错误:

Unchecked runtime.lastError while running tabs.highlight: No tab at index: 7355.

【问题讨论】:

    标签: google-chrome-extension google-chrome-app


    【解决方案1】:

    chrome.tabs.highlight 需要标签索引,而不是 tabId。您可以使用 chrome.tabs.get 将 tabId 转换为索引:

    chrome.tabs.get(tabId, function(tab) {
      chrome.tabs.highlight({'tabs': tab.index}, function() {});
    });
    

    【讨论】:

    • 请注意,chrome.tabs.highlight 中的回调应该是可选的,但由于 Chrome 错误,目前需要它:code.google.com/p/chromium/issues/detail?id=417564
    • 我只是希望这些是最后一个强制无用回调案例。我记得notifications API 中有类似的问题。
    【解决方案2】:

    另一个重要的事情(除了使用标签索引)是提供windowId。这在官方 chrome 文档中没有记录,但如果其他窗口或检查器处于活动状态,则会有所帮助。

    chrome.tabs.highlight({
      windowId: tab.windowId,
      tabs: tab.index
    }, function () {});
    

    【讨论】:

      【解决方案3】:

      此函数不使用选项卡 ID,而是使用选项卡索引(窗口内的位置)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多