function doSomething() { const copilotHeaderDivs = document.querySelectorAll('.AppHeader-CopilotChat'); const copilotHomePageDivs = document.querySelectorAll('.copilotPreview__container'); copilotHeaderDivs.forEach(function(div) { div.remove(); // Remove each matching div }); copilotHomePageDivs.forEach(function(div) { div.remove(); // Remove each matching div }); } if (document.readyState === "loading") { // Loading hasn't finished yet document.addEventListener("DOMContentLoaded", doSomething); } else { // `DOMContentLoaded` has already fired doSomething(); }