1

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

Miraj50
  • 4,257
  • 1
  • 21
  • 34
  • To get the favicon you can use tab.favIconUrl You can find all tab values here https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/Tab – regularjoe Sep 22 '17 at 08:56
  • @regularjoe I have already tried that. But it returns the url(basically the directory where it is stored). How does one get that image from that url? – Miraj50 Sep 22 '17 at 13:15
  • @Miraj I would recommend splitting your second question off (and providing more details on where and how you want to use it). – Xan Sep 22 '17 at 14:21
  • 1
    @Xan Okay, done :). I have asked another question based on that. – Miraj50 Sep 22 '17 at 17:11

0 Answers0