How to call a javascript function after the page loads with a chrome extension?

google-chrome, javascript

Solution

Both Chrome extensions and greasemonkey offer ways to specify when the script you inject if executed.

In Chrome extension, you set that in the manifest :

"content_scripts": [
    {
        "run_at" : "document_idle",

In GreaseMonkey compatible userscripts, you set that in the metadata

// @run-at document-end

In both cases, you just have to add this to your script if you want to ensure resources are loaded when your function is executed :

document.addEventListener('load', submitAction);

Problem

There's a function on a page that I want to call after it loads. I do not own the page, so I can't insert any html into it. Can you please provide specific examples how to do this with some chrome extension or greasemonkey? (function is `submitAction()`).

Original source