0

My content script is call to background script through chrome api message pass, here is my content script :

function getstorage() {
    chrome.runtime.sendMessage({action:'getlocalstorage',data:"datatopull"}, function(response){
        alert('response : ' + response.data);
    });
}

and my background script :

chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
 . . . . .
    }else(message.action=='getlocalstorage'){
        chrome.storage.local.get(message.data,function(item){
            return sendResponse({data:item[message.data]});
        });
    }
})

but i know the return(response.data) still not contain value because calling async function, how to deal with it ?

0 Answers0