While developing a chrome extension I used the following code in my background script:
session="abcd";
chrome.storage.sync.set({"session": session}, function () {
console.log("session set as: " + session)
});
chrome.storage.sync.get(["session"], ({data}) => {
console.log("session retrieved as: " + data.key)
});
The second function returns undefined. From my searches it appears that I am making some mistake while calling async function. But I am not able to identify it. How to write this code correctly?