最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I find out what causes jQuery-related message of "Use of Mutation Events is deprecated. Use Mutatio

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Jul 25, 2018 at 20:45 Dennis asked May 18, 2017 at 13:36 DennisDennis 8,12112 gold badges73 silver badges121 bronze badges 4
  • It's likely due to a third-party library using the deprecated events. See stackoverflow./q/19965211/215552, stackoverflow./q/18223315/215552, many others. I just searched on that error message and found those two. – Heretic Monkey Commented May 18, 2017 at 14:03
  • The error says your code uses obsolete DOM mutation events. – woxxom Commented May 19, 2017 at 2:42
  • 1 This seems like deja vu... Do a search of your code base (and those of the plugins you're using, etc.) looking for a mutation event name (e.g., "DOMAttrModified"). – Heretic Monkey Commented Jul 25, 2018 at 20:50
  • I found the offending line. Goes something like this: $('#main').on('DOMNodeInserted', function() {load_ui_globals();}); – Dennis Commented Jul 25, 2018 at 20:58
Add a ment  | 

1 Answer 1

Reset to default 5

Per ments 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论