wait for document.body existence

前端 未结 2 1620
清歌不尽
清歌不尽 2020-12-09 21:34

I wrote a chrome extension that works before the page is loaded (using the attribute \"run_at\": \"document_start\"). The problem is that I want to add a

2条回答
  •  独厮守ぢ
    2020-12-09 21:59

    You can use DOMContentLoaded event which is similar to $(document).ready()

    document.addEventListener("DOMContentLoaded", function(event) {
       console.log("DOM fully loaded and parsed");
    });
    

    MDN says

    The DOMContentLoaded event is fired when the document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading (the load event can be used to detect a fully-loaded page).

提交回复
热议问题