开发者

Check DOM element in Google Chrome Extension

I am trying to make a simple Google Chrome extension - like finding a specific e开发者_开发百科lement 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.


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
        }
});


Have you tried to put your code in window.onload event in "content_script.js"?

window.onload = function() {
   // your code
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜