I was working on a Firefox web-ext. I need to get the url and the favicon of the current tab in var variables.
Whatever I do, I am not able to return the url from the function where it is being calculated. All the answers to similar type of questions print the url inside the function itself. But I want it outside as I need to display it inside the popup (when extension is clicked) itself. Here is what I have been trying.
var addnewsite = document.querySelector('.addnewbutton');//invoking the button
addnewsite.addEventListener('click', addNEWsite);
/* generic error handler */
function onError(error) {
console.log('Error: ${error}');
}
function addNEWsite(){
}
function siteurl(){
browser.tabs.query({ currentWindow: true, active: true }, function (tabs) {
// console.log(tabs[0].url);
return tabs[0].url;//I have the tabs permission
});
}
var x = siteurl();
console.log(typeof x,x);
Also, I have seen that I can pass the url to another function but I can't get to return it. Is there a way to do it.
EDIT: Thanks to @Xan, it is now clear due to this