9951 explained code solutions for 126 technologies


chrome-extensionGet active tab ID


chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
  var tab = tabs[0];
  console.log(tab.id);
});ctrl + c
chrome.tabs.query

returns tabs list based on query

active: true, currentWindow: true

we want active tab

tab = tabs[0]

we expect only one tab in the result list, which is a curent tab

console.log(tab.id)

log tab id to console