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

188
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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