Execute in Content-Script after js form Website

Hey-ho,

how can i fire code in a content-script, after the js-code of the actual website has finished?

In Chrome it works fine with window.onload = function(){…}.
If the page has already a onload event, the onload event in the contentscript fire at last.
But in Firefox, the event will be overwriten. Only my own code will be executed.

What should I do?

Use addEventListener()


As the name says, it adds, not replaces, eventlisteners.

1 Like

sorry, been busy the last few days.

window.addEventListener(‘load’, function(){

This only seems to work on pages that load external scripts, like https://www.google.com/. And only if you update the page manually.
With simple HTML pages the function does not fire.

Possibly by the time the content script adds the event listener, the load event already fired? Perhaps check the readyState and if it is complete just run your function immediately rather than scheduling it to run on load.

Thank you.

I’m not dealing with this problem anymore.
What I found yet: https://stackoverflow.com/questions/27893300/gmail-chrome-extension-and-document-readystate