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

176
Views
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
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!