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

178
Vistas
What could cause Mutation Observer on entire document and subtree to not fire when child added?

Sometimes the mutation observer callback doesn't fire when I expect it to.

If I run this code in developer tools console:

// callback for mutations observer
 callbackForAllChanges = function (mutationsList, observer) {
  console.log("mutations: ", mutationsList);
};

// create mutation observer
 allChanges = new MutationObserver(callbackForAllChanges);


// attach mutation observer to document
  allChanges.observe(document, {
    childList: true,
      subtree:true
  });

// create new child
document.body.appendChild(document.createElement("div"));

I would expect callback to fire when I create a new child. But sometimes it does and sometimes it doesn't.

When I run the code in the devtools console while on stackoverflow it works: I see mutations: [MutationRecord] logged to the console.

When I go on twitter and run the above code in the devtools console, it doesn't seem to work: mutations: [MutationRecord] is not logged to the console.

What could cause Mutation Observer to not work on twitter?

To recreate issue

  1. Go to twitter
  2. Open the devtools console
  3. Paste the above code and see mutations: [MutationRecord] does not log

UPDATE

Now it works for me on twitter so seems intermittent.

UPDATE 2

It's stopped working again on twitter. I also found if I add a mutation observer to a div I create, that also doesn't work but works on other sites.
const newDiv = document.createElement('div')
newDiv.setAttribute('id','newDiv')
// callback for mutations observer
 callbackForAllChanges = function (mutationsList, observer) {
  console.log("mutations: ", mutationsList);
};

// create mutation observer
 allChanges = new MutationObserver(callbackForAllChanges);


// attach mutation observer to document
  allChanges.observe(newDiv, {
    childList: true,
      subtree:true
  });

// create new child
newDiv.appendChild(document.createElement("div"));

UPDATE 3

  • Mutation observer hasn't stopped working in incognito
  • Turning all extension off doesn't fix mutation observer when it's not working
  • Quitting and restarting chrome seems to fix Mutation observer when it stops working
  • Clearing cookies does not fix the issue
about 4 years ago · Juan Pablo Isaza
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