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

190
Visualizações
Read a text file line by line in a Chrome Extension

I am working on a Google Chrome Extension that will take an email address and loop through a whitelist to see if we get a match. I am working with functions inside a content.js script and I have a whitelist.txt file within the same directory as the manifest.json. I am attempting to iterate through each line of the whitelist.txt file but it is proving rather difficult with JavaScript. I am able to read the file and can log it to the console however when I attempt to iterate through each line it will break it up letter by letter. How would I go about iterating through the file line by line?

content.js 
  const url = chrome.runtime.getURL('whitelist.txt');

  fetch(url).then(function(response) {
      return response.text().then(function(text) {
        for (let i = 1; i < text.length; i++) {
          /* Logic for seeing if email is on list */
          console.log(text[i]); /* Outputs the file line by line letter by letter. */
          return (email.test(text[i]));
        }
        //console.log(text); /* Outputs the entire txt file to the console */
      });
    });

whitelist.txt

...
yahoo.com
yahoo.com.ar
yahoo.com.au
yahoo.com.br
yahoo.com.cn
yahoo.com.hk
yahoo.com.is
yahoo.com.mx
yahoo.com.ph
yahoo.com.ru
yahoo.com.sg
yahoo.de
yahoo.dk
yahoo.es
yahoo.fr
yahoo.ie
yahoo.in
...
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The text being returned is a string You can separate it word by word with the split() function

const words = text.split("\n"); //array of words
about 4 years ago · Juan Pablo Isaza Relatório
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