drew hintz
drew hintz

Reputation: 533

chrome.tabs.highlight giving error "No tab at index"

When calling chrome.tabs.highlight({'tabs': tabId}, function(){}); I'm getting this error:

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

Upvotes: 10

Views: 3729

Answers (3)

Felix
Felix

Reputation: 1267

Another important thing (in addition of using the tab index) is to provide the windowId. This is not documented in the official chrome docs, but helps if a different window or inspector is active.

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

Upvotes: 4

drew hintz
drew hintz

Reputation: 533

chrome.tabs.highlight requires a tab index, not a tabId. You can convert a tabId into an index using chrome.tabs.get:

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

Upvotes: 18

Xan
Xan

Reputation: 77531

This function does not take tab IDs, but instead the tab indices (positions within the window)

Upvotes: 1

Related Questions