致电//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
时,我收到此错误:
chrome.tabs.highlight({'tabs': tabId}, function(){});
答案 0 :(得分:8)
chrome.tabs.highlight需要制表符索引,而不是tabId。您可以使用chrome.tabs.get将tabId转换为索引:
chrome.tabs.get(tabId, function(tab) {
chrome.tabs.highlight({'tabs': tab.index}, function() {});
});
答案 1 :(得分:1)
此功能不采用标签ID,而是采用标签索引(窗口内的位置)
答案 2 :(得分:1)
另一个重要的事情(除了使用标签索引)是提供windowId
。正式的chrome文档中没有对此进行记录,但是如果其他窗口或检查器处于活动状态,则将有所帮助。
chrome.tabs.highlight({
windowId: tab.windowId,
tabs: tab.index
}, function () {});