Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
How to put JSON object restored from chrome.storage.local into a variable?

I'm trying to build a little chrome extension, and, shortly, I have a popup where the user is prompt to flag/unflag a set of checkboxes. A function than modify a JSON object according to checked/unchecked boxes and later saves it in chrome.storage.local.

So far so good; problems starts at a later stage, when I try to recover the stored data into the content_script. I managed to pass the object into an alert, but, in order for my script to work, I need that JSON to be stored back into a var.

This is the code I inserted in the popup.js and that works fine

chrome.storage.local.set({
        capacity: object
    }, function() {
        console.log('stored with chrome.storage.local');
      });

here's the code I have in the actual script:

var capacity;

load();

function load() {
chrome.storage.local.get('capacity', function(result){
        capacity = result.capacity;
        alert(result.capacity);
}

I'm trying to get capacity to be the same var it was on popup.js when I saved it, but after several attempts I only managed to get the values printed in the alert.

So my question is: is it possible to do this? Where am I getting this wrong?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda