Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

423
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!