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

293
Visualizações
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
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