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

176
Vistas
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
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