0
    (function getCloseBox (){
    let target = document.body;
    let MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
    let mutation = new MutationObserver((mutations)=>{
        mutations.forEach(function(mutation) {
            console.log(mutation.type);
        });
        if(document.getElementById("pb_layout")){
            console.log("it is found");
        }else{
            console.log("it is not found");
        }
    });
    let config = { attributes: true, childList: true,subtree: true ,characterData: true}
    mutation.observe(target, config);
})();

here in the if statement I am checking for the element which will load after an ajax call in a website but in that website, this element is loaded but the mutation observer not found the change in the body. Executing else statement only and This functionality is for an extension so I don't have a access to ajax response. Please help

the8472
  • 40,999
  • 5
  • 70
  • 122
janaravi
  • 106
  • 1
  • 8
  • 1. Is this code inside the *content script*? 2. It's possible to intercept ajax response by spoofing XMLHttpRequest prototype inside [code inserted in a ` – wOxxOm Jan 27 '18 at 11:12
  • yeah it is inside the content script ? why it is not getting the element and setinterval way also not working – janaravi Jan 27 '18 at 12:05
  • The code seems fine. Make sure there's no a second element with the same id - duplicates prevent getElementById from working. – wOxxOm Jan 27 '18 at 18:18
  • 1
    at what point in time do you register your callback? and have you made sure the body node does not get swapped in the meantime? – the8472 Jan 27 '18 at 18:30

0 Answers0