2

I am changing src of all images to '' using mutation observer. But browser is making the request to that image URL. How to block image requests from the browser?

Below is the code.

const observer = new MutationObserver(mutations => {
    mutations.forEach(({
        addedNodes
    }) => {
        addedNodes.forEach(node => {
            if( node.tagName == "IMG" ){
                node.setAttribute("data-src",src);
                node.removeAttribute('src');
            }                                      
        });
    });
});
observer.observe(document.documentElement, {
    childList: true,
    subtree: true
});
Vishnu
  • 11,614
  • 6
  • 51
  • 90

0 Answers0