Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
chrome.storage.sync.get value after return is always undefined

I am programming a chrome extension. It works good but i have a problem getting the value.

On installation it should set a default value. But here comes the problem: I cant get the value. logValue() should give the value to the console for testing, which it takes from getValue(). In the getValue() function, it works but if I return the value, it is undefined. (Details in the screenshot below.

What is my fault and how can I do it, that the value and type in the logValue() function is the same as in the getValue()?

And I am sorry for my bad english:)

Devtools output

Here you see, in the getValue() function it has the right value (1st time null and 2nd time the string of the object. But if I return it to the logValue() function which replaces a function to work with it, the value is only undefined.

And here is my code:

function logValue() {
    var x = getValue();
    y = JSON.stringify(x);
    console.log("Type: " + typeof (x) + "\nvalue: " + x);
}

function getValue() {
    debugger;
    chrome.storage.sync.get(['testObject'], function (result) {
        var value = result.testObject;
        console.log("Type: " + typeof (value) + "\nvalue: " + value);
        return value;
    });
}

function setDefaultValue(data) {
    debugger;

    data = JSON.stringify(data);
    chrome.storage.sync.set({
        'testObject': data
    }, function () {
        console.log('Value is set to ' + data);
    });
}

chrome.runtime.onInstalled.addListener(() => {
    debugger;
    chrome.storage.sync.set({
        'testObject': null
    }, function () {});

    data = {
        "data": [{
                "name": "Test1",
                "value": "Value1"
            },
            {
                "name": "Test2",
                "value": "Value2"
            }
        ]
    };
    logValue();
    setDefaultValue(data);
    logValue();

});

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda