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

174
Views
set chrome.storage.local.set key from function variable chrome extension

Is there a way to set the key for chrome.storage.local.set via a string that is in a variable.

For instance, I want to send a file name and a key name into a single function to store the results into chrome.local.storage.set. It would look something like this.

Call:

setURLS('fileLocation', 'listofurls');
setURLS('secondFileLocation', 'listofsomethingelse');

Method:

function setURLs(fileName, keyName) {
    let textFile = new XMLHttpRequest();
    textFile.open('GET', fileName , true);
    textFile.onreadystatechange = function(){
        if(textFile.readyState === XMLHttpRequest.DONE && textFile.status === 200){
            let dictionaryArray = textFile.responseText.split(',');
            chrome.storage.local.set({keyName: dictionaryArray}, function (){});
        }
    }
    textFile.send(null);
}

It doesn't like to use the string from the variable in the function header. I have to manually set the name of the key which duplicates code for all files that I would like to pull data from.

I hope that I explained it well enough to understand.

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!