I write the set local storage function in a public lib, when I invoke this function in google chrome extension, the value did not set to local storage:
const LocalStorage = {
setLocalStorage: async (key: string, value: string): Promise<string> => {
return new Promise((resolve, reject) => {
chrome.storage.local.set({
key: value
}, function () {
resolve("");
});
});
},
}
export default LocalStorage
I invoke this function like this to set the value:
await LocalStorage.setLocalStorage("key", "value to set").then(() => {
LocalStorage.readLocalStorage("key").then((result) => {
alert(result);
});
});
but the result was '', did not show the value value to set, why this did not work. when I use this original function to set in context, it works:
chrome.storage.local.set({
"key":"value to set"
},async function(){
});