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

105
Vistas
Add event listener to a button on a Page Chrome Extension

In content.js, I am trying to add an event listener to a button on the page but I keep getting this error:

Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')

I have tried to put it in document.addEventListener('DOMContentLoaded',afterDOMLoaded); but DOMContentLoaded never fires in the content.js script. How can I add an event listener to a button on the page?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should show how your content.js is executed.

Maybe, the page has already DOMContentLoaded when your script is inejcted. The injection timing can be specified in manifest file. If your manifest file is the following, your content.js is injected immediately after the window.onload event fires, that is after DOMContentLoaded. Refer https://developer.chrome.com/docs/extensions/mv3/content_scripts/.

"content_scripts": [
{
  "matches": ["https://*/*"],
  "run_at": "document_idle",
  "js": ["content.js"]
}

If your manifest is like the above, you do not need event listener, just write the code in content.js script instead.

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