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

121
Vistas
What is the proper way of updating values using chrome.storage API?

The code below is not doing what I expect:

chrome.runtime.onStartup.addListener(() => {
  chrome.storage.local.set({
    foo: {},
  });
});

chrome.tabs.onUpdated.addListener(async () => {
  const foo = await chrome.storage.local.get("foo");
  foo[Math.floor(Math.random() * 10).toString()] = "data";
  chrome.storage.local.set({
    foo: foo,
  });
});

It results in this data:

{
    "2": "data",
    "foo": {
        "5": "data",
        "foo": {
            "3": "data",
            "foo": {
                "2": "data",
//...
// (the rest omitted deliberately for not occupying too much space)

I don't get it, does this result makes sense? Probably I'm thinking the wrong way about it, but I can't find out what's my misunderstanding. If I'm setting foo which is a key already available in the object, shouldn't it be updated (and not get nested)? My end goal is a structure like this(please forget about the Math.random, that was just for the example):

{
  foo: {
    "AB4": "data1",
    "5C2": "data2"
  }
}

and I want it to turn into something like this after update:

{
  foo: {
    "AB4": "data1",
    "5C2": "data2",
    "DA1": "data3"
  }
}
about 4 years ago · Santiago Gelvez
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