My program is supposed to get the URL of the tab that is currently open and store it in a variable to be manipulated later. I printed the outcomes into a component to debug.
var url = "url not set";
// finds active tab url
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function(tabs)
{
//document.getElementById("basicUsage").innerHTML = url; output 1
url = tabs[0].url;
//document.getElementById("basicUsage").innerHTML = url; output 2
});
//document.getElementById("basicUsage").innerHTML = url; output 3
The URL is printed when only output 2 is uncommented (as expected) but the output is "url not set" when only output 3 is uncommented. The new URL is saved in the global variable so I don't understand why it's not outputted when the line is outside chrome.tabs.query.
The variable used within the chrome.tabs.query function is the correct one (I checked it using output 1).
It seems as though the program "ignores" the entire function.