I'm writing a Chrome Extension. I have the following piece of code.
function getCurrentTab() {
var r;
chrome.tabs.query({
active:true,
currentWindow:true
},function (tabs) {
r=tabs[0];
console.log(r);
});
return r;
}
console.log(getCurrentTab());
I expect this function to return the active tab. Unfortunately the attribution inside the callback function doesn't affect r from the parent function getCurrentTab
and I can't figure out why is that.
At the moment this code writes to console:
undefined
Object {active: true, height: 954, highlighted: true, id: 16, incognito: false…}
Desired result would be:
Object {active: true, height: 954, highlighted: true, id: 16, incognito: false…}
Object {active: true, height: 954, highlighted: true, id: 16, incognito: false…}