I'm trying to use execute a simple querySelector inside a contentscript of my chrome extension:
const el = document.querySelector("#sections > ytd-guide-section-renderer:nth-child(1)");
console.log(el);
When visiting the main youtube page the querySelector works fine and I get my result. However when visiting the "subs" or "trends" page the querySelector returns null
. Executing the script manually inside the console works fine.
console.log(document.body)
also works on the subs/trends pages. I also tried adding a delay but that didn't really help at all.
For testing purposes I added "matches": ["<all_urls>"]
so the script should be able to run on any site.
Any ideas?