I am trying to get extension preferences in content script by asking from background.js.
contentscript.js
chrome.runtime.sendMessage({'action' : 'preferences'},
function(prefs) {
console.log(prefs);
}
);
background.js
function onRequest(request, sender, callbackOfContentScript) {
chrome.storage.sync.get(null, function(items){
callbackOfContentScript(items);
});
}
chrome.runtime.onMessage.addListener(onRequest);
console.log
in content script returns undefined
.
What is the issue here?