I'm making a Chrome extension that makes a lot of use of getting the id of the current active tab in the current active window. Using chrome.tabs.query wrapped around a lof of logic makes my code messy, but putting it in it's own function to return the current tab always returns undefined - why?
function _getCurrentTab(){
var theTab;
chrome.tabs.query({active:true, currentWindow:true},function(tab){
theTab = tab;
});
return theTab;
};
console.log(_getCurrentTab());
Can anyone help with this?