I'm creating a Google chrome extension. The extension doesn't need to be active on all websites and thus instead of adding a "content_scripts"
entry to manifest.json
, I've added a "permissions"
entry like this:
"permissions": [
"activetab"
]
I need to wait for DOM completion since my extension tries to get some data from DOM.
In my content script I've added the following code to wait for DOM creation:
window.addEventListener('DOMContentLoaded', function () {});
The problem is that the above trick works if somebody clicks my extension during page load, but if somebody opens my extension after the page has fully loaded, then my content script won't do anything, since the DOMContentLoaded
event has already occured.
What should I do to make sure the code in my content-script fires irrespective of the fact that the page has loaded or not.