How do I find out what causes jQuery-related message of "Use of Mutation Events is deprecated. Use MutationObserver instead"?

Dennis picture Dennis · May 18, 2017 · Viewed 8.1k times · Source

I get this message when loading a typical page on my browser:

Use of Mutation Events is deprecated. Use MutationObserver instead.

Line Number where this message happens to be thrown is given as: jquery-3.2.1.js:5062:6

Looking at jQuery source, this is the code it contains, where the offending line is elem.addEventListener( type, eventHandle );

// Init the event handler queue if we're the first
if ( !( handlers = events[ type ] ) ) {
    handlers = events[ type ] = [];
    handlers.delegateCount = 0;

    // Only use addEventListener if the special events handler returns false
    if ( !special.setup ||
        special.setup.call( elem, data, namespaces, eventHandle ) === false ) {

        if ( elem.addEventListener ) {
            elem.addEventListener( type, eventHandle );
            # ^^^^^ the line that throws the Mutation Observer message
        }
    }
}

How do I find out the code responsible for triggering this message?

Answer

Dennis picture Dennis · Jul 25, 2018

Per comments under the question:

Search your codebase for the deprecated DOM events, i.e the regex of:

DOMAttrModified|DOMAttributeNameChanged|DOMCharacterDataModified|DOMElementNameChanged|DOMNodeInserted|DOMNodeInsertedIntoDocument|DOMNodeRemoved|DOMNodeRemovedFromDocument|DOMSubtreeModified

It will show you offending lines that trigger deprecated events.