1

In chrome extension I need background.js to answer a message with current value of local storage, but:

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        if(request.msg == 'is_hidden'){
            chrome.storage.local.get('is_hidden',function(is_hidden){
                if(typeof is_hidden !== 'undefined'){
                    sendResponse(is_hidden);
                }
            }
        }
    }
);

... does not work. Doesn't send response.

But this does:

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        if(request.msg == 'kiss me'){
            sendResponse('*kiss*');
        }
    }
);

Seems like sendResponse that is in callback of storage.local.get loses it's context...

How do I make it work?

Flash Thunder
  • 11,672
  • 8
  • 47
  • 91
  • possible duplicate of [Chrome Extension Message passing: response not sent](http://stackoverflow.com/questions/20077487/chrome-extension-message-passing-response-not-sent) – Xan Jan 28 '15 at 14:05
  • thank you, that saved my day! Should I delete it? – Flash Thunder Jan 28 '15 at 14:32

0 Answers0