samedi 26 septembre 2020

Chrome Extensions "chrome.storage.local" data updating trouble

I am working on one chrome extension and i need to use local storage to send data from options page to background scritps.

Options page script:

function addToStorage(key, val){
    let obj = {};
    obj[key] = val;

    chrome.storage.local.set( obj, function() {
      if(chrome.runtime.lastError) {
        console.error(
          "Error setting " + key + " to " + JSON.stringify(val) +
          ": " + chrome.runtime.lastError.message
        );
      }
    });
}

Background:

chrome.storage.local.get('code', function(code) {
    ... with code.code ...
});

For example: Now chrome.storage.local code value is abcd
I'm performing addToStorage('code', '1234') from options page script
After that in background script value code only will change when i manually click "update" at chrome extesions page

How can i automatically get actual data at background script?




Aucun commentaire:

Enregistrer un commentaire