【发布时间】: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
调用chrome.tabs.highlight({'tabs': tabId}, function(){}); 时出现此错误:
Unchecked runtime.lastError while running tabs.highlight: No tab at index: 7355.
【问题讨论】:
标签: google-chrome-extension google-chrome-app
chrome.tabs.highlight 需要标签索引,而不是 tabId。您可以使用 chrome.tabs.get 将 tabId 转换为索引:
chrome.tabs.get(tabId, function(tab) {
chrome.tabs.highlight({'tabs': tab.index}, function() {});
});
【讨论】:
notifications API 中有类似的问题。
另一个重要的事情(除了使用标签索引)是提供windowId。这在官方 chrome 文档中没有记录,但如果其他窗口或检查器处于活动状态,则会有所帮助。
chrome.tabs.highlight({
windowId: tab.windowId,
tabs: tab.index
}, function () {});
【讨论】:
此函数不使用选项卡 ID,而是使用选项卡索引(窗口内的位置)
【讨论】: