I'm trying to write a Google chrome extension that grabs the element in the page by its class name. The idea is to use the content script to grab these elements and pass the messages to the extensions and pop up. However, my content script always end up executing before the entire page is loaded so I can't grab the elements that I want. I try using window.loaded
and document.loaded
but it didn't work. I also tried wait an interval but the script always ended up executing at the exact same stop point.
// my content script
if (document.readyState == "complete"){
var board_name_arr = [];
var node = document.getElementsByClassName('Board');
for (var i = 0; i < node.length; ++i){
var board_name = node[i].getElementsByClassName('boardName')[0].textContent;
board_name_arr[i] = board_name;
}
if (Object.keys(board_name_arr).length){
alert("found board");
}
}
Is there a way to force it to run after ? Or should I not be using content script approach?