I am trying to write a Chrome extension that modifies the appearance of tweets on Twitter.
window.addEventListener('load', myMain, false)
function myMain() {
console.log(document.getElementsByTagName('article'))
console.log(document.getElementsByTagName('article').length)
for (const article of document.getElementsByTagName('article')) {
console.log('print something if this code is ever reached')
console.log(article)
}
}
Produces the following output:
Hence console.log(document.getElementsByTagName('article'))
retrieves every articles element, but the HTMLCollection CANNOT be iterated over.
I have seen other StackOverflow threads that suggest that the script must run after the page has loaded (e.g.: Iterate over HTMLCollection in custom element, HTMLCollection appearing in console with many elements but has length 0). But Twitter seems to be forever loading, so that solution does not work here. Is there any way to retrieve the content of document.getElementsByTagName('article')
given that the Javascript is clearly retrieving something in order to be able to print it to the console?