Sunday 29 October 2017

javascript - How do I call chrome.storage.sync.get and assign variables on page load?

I have a page that should only load a certain portion if a
setting is true. These settings are found in
storage.




However I am unable to
retrieve these settings when loading the page.
I have tried the
following:



var permission =
true;
chrome.storage.sync.get({
history: true
},
function(items) {
permission =
items.history;
});



but
permission will always equal true when the page loads. If I put a call to another
function to print the value of permission, this will not be called until
after.



I call this function as well as the
functions loading the parts of the page
using



document.addEventListener('DOMContentLoaded',
function () {


I think
the problem is that the function is not called in time, but I don't know how to resolve
this.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...