lundi 4 juillet 2016

get value from chrome.storage.local without using the async function

I am trying to get value from chrome.storage and store it in a variable inside content_script.js. My approach was as below (poor me, this was the only approach I could come up with):

function editVariable(text, variableName) {
  var targetVariable;
  chrome.storage.local.get(function(data) {
    targetVariable = data[variableName];
    console.log(targetVariable);
  });
  targetVariable.content_text = text;
  targetVariable.content_type = "Edited Marked Content";
  return targetVariable;
}

Clearly, the value fetched from chrome.storage was assigned to the variable targetVariable after the following lines of code was ran. So how can I get the job done in a smart way?

Heaps of thanks in advance!




Aucun commentaire:

Enregistrer un commentaire