Currently facing an issue with my Chrome extension where I am using angularJS in the popup. My goal is to retrieve the URL of the active tab and display it in the popup. Here is the code snippet I am using to achieve this:
var link;
var query = { active: true, currentWindow: true };
function callback(tabs) {
var currentTab = tabs[0];
var url = currentTab.url;
console.log('URL: ' + url);
link = url;
}
chrome.tabs.query(query, callback);
$scope.link = link;
console.log('URL AFTER THE CALL: ' + $scope.link);
This code belongs to the MainController that manages the popup. I am attempting to access the URL in popup.html using the $scope.link variable, but I am only getting the data within the callback function. The output I am receiving is as follows:
URL AFTER THE CALL: undefined
URL: http://stackoverflow.com/questions/ask?title=angular%20js%20url%20in%20popup
It seems like the link assignment and the console log 'After call' are being executed before the callback function is finished. I am stuck on how to resolve this issue.