Reputation: 22698
I am trying to make a simple Google Chrome extension - like finding a specific element on the page and display an alert.
My problem is that the specific page loads relatively slow (having also some AJAX behind).
How can I make my check only when all the page is loaded?
I tried "run_at" : "document_idle"
in my manifest file, but with no success. It shows me the message, before the whole page loads.
I was thinking to check every second (or something) the whole DOM elements, but is this a feasible solution? I think it will slow down the page...
Thanks.
Upvotes: 0
Views: 2724
Reputation: 111265
If that element does not exist on the page when you click "view source", then one way of catching it would be listening to DOMSubtreeModified
event, which fires each time DOM is modified:
document.addEventListener("DOMSubtreeModified", function(event){
if(document.getElementById("my_element")) {
//element is added
}
});
Upvotes: 2
Reputation: 10170
Have you tried to put your code in window.onload event in "content_script.js"?
window.onload = function() {
// your code
};
Upvotes: 1