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

233
Visualizações
Can you track what caused a mutation record with MutationObserver?

I am working on a Google Chrome extension and have something like the following code below. While there is nothing wrong with the code below there is a slight issue I am having trouble resolving.

I'm using this code to detect if the reports-content class was changed from losing focus on an input control or if a timer was the action that caused the change.

The problem is, I only want to do something if the change was the result of losing focus on the input control and NOT the timer.

I want to do this so I can loop through different inputs and only try new inputs once the 'reports-content' has updated with new data.

The 'timer' is outside my control since it's on a third party website (tradingview.com), which happens to be using React framework in case that is important. Every-time the price changes it will detect as a mutation to the object I'm checking, which is not a bug, that is good that it does that, but I need to be able to discern which mutation was caused from that (timer/event/change), and which came from the input control losing focus.

enter image description here

Below is an example of the two mutation records I currently see, one caused by the event and the other the timer or (price change noticed event).

enter image description here

Below this is an example of what the reports-content looks like.

enter image description here

//When the DOM is ready set the mutation listner.
$(document).ready(function(){
    console.log("JQuery Ready");

    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(record => {
            var recordTarget = record.target;
            
            if(record.addedNodes.length>0){
                if(recordTarget.classList.contains("reports-content")){
                    console.log(recordTarget);
                    console.log(record);
                };
            }
                    
        });
    });

    //Use mutation observer on 'body' to wait for the existence of the .reports-content class node
    var target = $('body')[0];
    var config = {
        childList:true,
        subtree: true
    };
    observer.observe(target, config);
});
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