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.