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

422
Vistas
How to store a map in a Chrome Extension using storage.sync?

I would like to store some settings for sites individually and my idea was to store a map with the domain names as keys and the settings as value using storage.sync from the Chrome API.

When I try to access a map I just retrieved using storage.sync.get I get the error:

Error handling response: TypeError: result.sites.get is not a function

In the documentation(link to highlight) it is mentioned that data can be stored as objects. I'm not sure what the problem is since maps are objects:

var map = new Map([[1,2],[3,4]]);
console.log(map instanceof Object); //true

Here I read that serialization is a problem when you try to store objects using storage.local. I don't know if this should be a problem with storage.sync though.

Here's the code I'm trying to run:

var siteList = new Map();

siteList.set('site1', {settings: "foo"});
siteList.set('site2', {settings: "bar"});

chrome.storage.sync.set({sites: siteList}, function() {
    console.log("Map set");
});
        
chrome.storage.sync.get(['sites'], function(result) {
    console.log(result.sites);
    console.log(result.sites.get('site1')); // This yields the error
});

As you can see I also console.log result.sites, this resulted in a [[Prototype]]: Object that looks like this:

constructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
valueOf: ƒ valueOf()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
__proto__: (...)
get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()

If someone knows if it is possible at all to store maps using storage.sync and if so, how to do it, I'd be glad to hear it!

~Naitzirch

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