//this is in the popup
function getURL(){
var url;
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
//gets a list containing the active page and assigns it to tabs where the first place is the active tab
chrome.tabs.sendMessage(tabs[0].id, {type: "getURL"}, function(answer) {
//sends a messge to the viewed in order to get its url
url = answer;
});
});
return url;
}
//this is in the content script of the extension
chrome.runtime.onMessage.addListener(
function(message, sender, sendResponse) {
if(message.type == "getURL")
{
console.log(window.location);
sendResponse(window.location.origin);
}
}
);
so the problem im encountering is when i run the getURL func it returns undefined and i assume its beacuse it reaches the return before getting the answer how would i make this function always return the url is there some way to make it "wait" for the answer?