The window
object of your content script is not the same as the one of your page. From the content script documentation:
It's worth noting what happens with JavaScript objects that are shared by the page and the extension - for example, the
window.onload
event. Each isolated world sees its own version of the object.
Therefore listening for this event in your content script won't work as you intent, since it's not the one you want.
It doesn't matter anyway: you can specify at which point your script is executed via the run_at
option. For example, if you choose to run it at document_idle
, then you're guaranteed it's executed after the window.onload
event of your page.
In other words, you can simply stop using the window.onload
event, and directly run the code you need.