Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda