First Post, so forgive me for any general practices that I haven't followed.
Also very new to Chrome extension and Javascript so apologies for my noob question
I have the following code but getting the console is say undefined
function getFromStorage(key) {
chrome.storage.sync.get(key, function (r) {
const returnVal = r[key]
console.log(returnVal)
return returnVal
})
}
chrome.contextMenus.onClicked.addListener((selectionText) => {
var Val = getFromStorage("value")
console.log(Val)
});
But when I run the chrome.storage.sync.get in the listener, it works fine. I have a few values from storage that I want to grab so thought a function would be better.
btw, using Manifest V3
Thank you in advance