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

101
Views
How to put JSON object restored from chrome.storage.local into a variable?

I'm trying to build a little chrome extension, and, shortly, I have a popup where the user is prompt to flag/unflag a set of checkboxes. A function than modify a JSON object according to checked/unchecked boxes and later saves it in chrome.storage.local.

So far so good; problems starts at a later stage, when I try to recover the stored data into the content_script. I managed to pass the object into an alert, but, in order for my script to work, I need that JSON to be stored back into a var.

This is the code I inserted in the popup.js and that works fine

chrome.storage.local.set({
        capacity: object
    }, function() {
        console.log('stored with chrome.storage.local');
      });

here's the code I have in the actual script:

var capacity;

load();

function load() {
chrome.storage.local.get('capacity', function(result){
        capacity = result.capacity;
        alert(result.capacity);
}

I'm trying to get capacity to be the same var it was on popup.js when I saved it, but after several attempts I only managed to get the values printed in the alert.

So my question is: is it possible to do this? Where am I getting this wrong?

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!