I am building a Chrome extension and in my contentScript, I have a function which loops all the <link>
elements and check whether it has rel="preconnect"
attribute. If true, the icon of the extension will change.
The contentScript runs at document start and the function. The function runs onDomLoaded
. When the prerender is directly in HTML code, the extension works perfectly. However when prerender is generated by JS, the icon wont change. Probably because the script is not fully loaded when onDomLoaded happens.
However when I use window.onload instead, it is really slow and the icon changes with a delay because it wait for the scripts to be fully loaded. How to deal with that situation and wait only if needed?
Manifest
content_scripts":
[{
"matches": ["https://*/*"],
"run_at": "document_start",
"js": ["js/contentScript.js"]
}]
ContentScript
document.addEventListener("DOMContentLoaded", function(event) {
//here I loop the page and if preconnect found, change the icon
)};