new MutationObserver(callback) then observer.observe(node, options). The options choose what to record, and at least one type is required or observe() throws a TypeError:
childList: nodes added or removed.attributes: attribute changes, optionally narrowed byattributeFilter.characterData: text node data.subtree: also watch every descendant, not justnode.attributeOldValue,characterDataOldValue: put the previous value inrecord.oldValue. These andattributeFilterimply their type.
Batching. Each mutation runs queue a mutation record: for every observer whose options match, it appends a MutationRecord to that observer's record queue, then queues a mutation observer microtask. A per-agent flag means only the first mutation actually queues it. That microtask runs at the next microtask checkpoint, after the current script returns, and calls each observer with all of its records, in observer creation order. A loop of 100 append() calls therefore yields one callback with 100 records, and the callback can't run in the middle of your code.
Records describe DOM operations, not values. A property that doesn't reflect an attribute, like an input's value or checked, changes no DOM and produces nothing; setting an attribute to the value it already has still produces a record. moveBefore() produces two childList records, a removal and an insertion.
takeRecords() returns and empties the queue (do it before disconnect() if you need the pending ones); disconnect() stops observing and discards them.
Uses: reacting to third-party or framework-rendered DOM, editors, testing utilities, and polyfills. Custom elements that only care about their own attributes use attributeChangedCallback, which runs synchronously before setAttribute() returns. Legacy: mutation events (DOMNodeInserted and friends) fired synchronously for every change; Chrome 127, Firefox 140 and Safari 26 removed them.