What are the potential consequences of using PHP to block popups that are generated by third-party JavaScript on a website?

When using PHP to block popups generated by third-party JavaScript on a website, potential consequences may include breaking the functionality of certain scripts that rely on popups for important user interactions. It may also lead to conflicts with the third-party scripts and cause unexpected behavior on the website.

// Block popups generated by third-party JavaScript
function block_popups() {
    echo '<script>
            window.addEventListener("load", function() {
                document.querySelectorAll("script[src*=\'third-party-script.js\']").forEach(script => {
                    script.onload = function() {
                        // Block popups here
                    };
                });
            });
          </script>';
}

add_action('wp_footer', 'block_popups');