0

I am developing an internal chrome devtools extension.

I have a panel which should show the URL of the page being debugged. And a background page. here is part of the panel.js script :

button.addEventListener('click', function() {
    chrome.extension.sendMessage( {'action':'get_url'}, function(response) {
        console.log(response);
        input.value = reponse;
    });
});

in my background.js script :

onRequest = function(request, sender, callback) {
    var url = 'default';
    if (request.action == 'get_url') {
       chrome.tabs.query({'active':true}, function(tabs) {
          url = tabs[0].url;
       });
       callback(url);
    }
};

chrome.extension.onMessage.addListener(onRequest);

All I am getting is 'default' but in the debug tools I can see callback is called with the url I expected.

What am I missing ?
I am new to chrome extension development, any advice would be appreciate. Thanks for your help.

Dionys
  • 3,083
  • 1
  • 19
  • 28
  • thank you guys. I did search if my question was already asked but did not find any. Would you mind giving tips on how to do effective search ? for instance with my issue what did you type ? – Dionys Oct 10 '14 at 07:53
  • If you know the answer, then it is easy to find the duplicate: `chrome extension onMessage return true` to find one of the many duplicates for one part of your question (via Google), and `chrome.tabs.query result not available` to find the other. – Rob W Oct 10 '14 at 08:09

0 Answers0