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

118
Views
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
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!