Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

329
Visualizações
MutaitionObserver.observe() not called in Chrome

I'm working with a jQuery plugin named Notify.js. The plugin create messages in the DOM and removes them on click.

I've created a button that will remove all messages. The button should only exist when there are more than two messages.

I've added a MutationObserver to check if the messages container has < 3 children and if so, the button should be removed.

That works well in Edge, Firefox and Opera but not in Chrome.

After canceling the Chrome Options of accelerating hardware and allowing programs to work in the background, the feature works on my computer, but not for my team mates.

Help would be much appreciated.

function message(text, type, obj_id) {
    var auto_hide = true;
    var auto_hide_delay = 10000;
    if (type == "error") {
        auto_hide_delay = 60000; 
    }

    var notify_properties = {
        clickToHide: true,
        autoHide: auto_hide,
        autoHideDelay: auto_hide_delay,
        elementPosition: "bottom center",
        globalPosition: "bottom left",
        className: type,
        showAnimation: "slideDown",
        showDuration: 400,
        hideAnimation: "slideUp",
        hideDuration: 200,
        gap: 2,
    };

    handle_close_all_messges();
    if (obj_id == undefined || $("#" + obj_id).length == 0) {
        $.notify(text, notify_properties);
    } else {
        $("#" + obj_id).notify(text, notify_properties);
    }
}
function handle_close_all_messges() {
    const notifyjs = document.querySelector('.notifyjs-corner');

    if (notifyjs && notifyjs.childElementCount > 2) {
        create_notifyjs_observer();
        create_messages_container();
        create_close_all_msgs_btn();
        add_notifyjs_to_container();
    }
}
function create_notifyjs_observer() {
    if (document.querySelector('.messages-container')) {
        return;
    }

    const MutationObserver = window.MutationObserver || window.WebKitMutationObserver; 
    const observer = new MutationObserver(onMutationObserved); 
    const notifyjs = document.querySelector('.notifyjs-corner');
    const options = { childList: true, subtree: true };
    
    observer.observe(notifyjs, options);
}

function onMutationObserved (mutations_list) {
    for (let mutation of mutations_list) {
        if (mutation.type === 'childList') {
            const notifyjs = document.querySelector('.notifyjs-corner');
            if (notifyjs && notifyjs.childElementCount < 3) {
                delete_close_all_msgs_btn();
            }
        }
    }
}

Link to full code: https://jsfiddle.net/a5eLpq4z/

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda