Chrome extension: background.js does not accept new values ​​from localStorage

There was a big problem when I update my local storage on the options page in order, the new values ​​are saved, but my background.js keep the values ​​of the first load, even if I put something like:

var value = localStorage['item'];

When I update the extension, this is normal, but very annoying ...

Are there any errors in this matter?

Hi

+5
source share
1 answer

? , script , . , , localStorage, . localStorage .
, , ....

// the following line will only be executed when the extension first loads
var value = localStorage['setting'];

function updateSetting () {
    value = localStorage['setting'];
}

localStorage['setting']=Math.random();
chrome.extension.getBackgroundPage().updateSetting();
+6

All Articles