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

193
Views
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 answers
Answer question

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 Report
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!