Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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()).

like image 846
Yet Another User Avatar asked May 04 '13 16:05

Yet Another User


1 Answers

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);
like image 86
Denys Séguret Avatar answered Nov 09 '22 22:11

Denys Séguret