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

295
Views
How to query email addresses in a webpage with JavaScript?

I am building a Chrome Extension that should be able to pull any email address listed on the background page.

I found that using a RegEx to scan the whole document is a very expensive operation and the website crashes.

Why am I scanning the whole document?

Remember, the extension is working on top of websites I did not build, so I do not know where the developer put the email. It could be on an tag, or a

tag, or in a ... the options are infinite. Therefore, I can't do a simple document.getElementsByTagName() or any similar query.

One way I thought of reducing the operation cost was to identify in which HTML tag the email(s) are in. I thought of using an Xpath and select all nodes with text that contains an '@', since '@' is a character that all emails have... then, I only have to compare those nodes' textContent with my email RegEx to see if there is a match.

Still, when I use a

Xpath = //text()[contains(.,'@')]

or any variant of that expression, I don't only get the nodes with visible text containing an '@', but also the nodes that have hidden information containing @.

Botton line, the operation is still very costly and is crashing the background pages.

I did use this procedure to fetch phone numbers and it works just fine. I imagine it is because scanning for numeric values is not as expensive since 99% of the website content is letters.

Am I thinking correctly about how to approach this? Does anyone have a better alternative?

about 4 years ago · Juan Pablo Isaza
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!