How can I detect the moment a specific DOM node has been downloaded by the browser, while the page is still loading?

279 Views Asked by At

I am writing a user script which needs to access specific DOM nodes on the page. To reduce latency and page re-layouting, I want to set it to // @run-at document-start instead of the usual // @run-at document-end, and run my code as soon as the DOM node I need has been downloaded from the server.

If I just wait for a DOMContentLoaded event, it will wait for the whole page to be downloaded; this is effectively the same as // @run-at document-end. I want to run my code at an earlier time, right when the browser’s parser encounters the closing tag of the element I want.

Is there a way to accomplish this more elegant than polling querySelectorAll from a MutationObserver callback?

0

There are 0 best solutions below