0

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(){
         
      });
wOxxOm
  • 53,493
  • 8
  • 111
  • 119
Dolphin
  • 13,739
  • 26
  • 110
  • 272

0 Answers0