Struggling with Chrome storage handling, I have reviewed the newest documentation for Chrome storage and implemented the following code snippet (found within an AJAX call success function, where info.userName is a value fetched from my backend program):
chrome.storage.local.set({ "userName": info.userName }, () => {
chrome.storage.local.get("userName", function(data) {
console.log(data.userName)
});
});
However, the console.log() consistently returns undefined, despite my belief that info.userName holds a value. I also attempted this alternative approach, which proved to be ineffective:
chrome.storage.local.set({ "userName": info.userName });
chrome.storage.local.get("userName", function(data) {
console.log(data.userName)
});
The issue appears to be with the set function failing to store anything locally. Any insights on resolving this?
Finally resolved the issue - the culprit was that the value of info.userName was not compatible with JSON. After rectifying this, the initial code snippet now functions correctly. Appreciate the feedback provided below!