chrome.tabs.highlight给出错误"索引没有标签"

dre*_*ntz 6 google-chrome-extension google-chrome-app

在调用时chrome.tabs.highlight({'tabs': tabId}, function(){});我收到此错误:

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

dre*_*ntz 10

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

chrome.tabs.get(tabId, function(tab) {
  chrome.tabs.highlight({'tabs': tab.index}, function() {});
});
Run Code Online (Sandbox Code Playgroud)

  • 请注意, chrome.tabs.highlight 中的回调应该是可选的,但由于 Chrome 错误,它目前是必需的:https://code.google.com/p/chromium/issues/detail?id=417564 (2认同)