I'm writing my first Firefox extension and I want to make sidebar disappear from Youtube where video recommendations are. Every time I open a video my script is injected into a page but sidebar stays unaffected until I reload the extension from about:debugging.
script works on some elements like search bar without reloading which has the id of "center" as I wrote in the code snippet below.
function hideContents() {
//works instantly
let center = document.getElementById("center");
center.style.display='none';
//does not work until reload
let secondary = document.getElementById("secondary");
if (secondary) {
secondary.style.display = "none";
}
}
I tried using MutationObserver, setTimeout, Event listeners to check if page was fully loaded but nothing worked. I feel like waiting for a page to load is not a solution and I'm missing out other detail that I don't know.
What do you suggest?
Edit: I solved the issue by changing one line of code
secondary.style.display = "none";
to
secondary.parentNode.removeChild(secondary);