Chrome Extension: The Js Script Fires Too Early Despite Run_at: Document_idle
In theory, if I set run_at, the .js that I use to select an element on the page should fire after the page is completely loaded. But it doesn't appear to be the case. In my conten
Solution 1:
run_at: "document_idle"
guarantees that the script is executed after DOMContentLoaded
event that signals that all static DOM content is parsed and available.
If an element doesn't exist yet, this means that it's being added later dynamically, by the page's own code.
Obviously, Chrome has no way to predict when (if ever!) a page is in a "finished" state. You need to set your own criteria (like "when #topcard
appears).
Having said that, your strategy should be as follows:
Check if the element already exists. If it does, process it and you're done.
Set up a listener for changes in the document. This is done through
MutationObserver
s, and I highly recommend themutation-summary
library for simplicity.
Post a Comment for "Chrome Extension: The Js Script Fires Too Early Despite Run_at: Document_idle"