Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript - how Greasemonkey works

I read "Dive into Greasemonkey" (by Mark Pilgrim) written in 2005. It mentions that Greasemonkey wraps a user script in an anonymous function wrapper. Does Greasemonkey insert the wrapper into the source JavaScript code or add it as any event handler such as window.onload?

like image 879
Paul Avatar asked Jul 14 '10 17:07

Paul


People also ask

How do I read a script on Greasemonkey?

To access Greasemonkey's management pane, click on the downward arrow on the right side of the button Greasemonkey to the right of your URL bar and select Manage User Scripts. This opens a tab with a list of your scripts.

Is Greasemonkey the same as Tampermonkey?

Tampermonkey is used to run so-called userscripts (sometimes also called Greasemonkey scripts) on websites. Userscripts are small computer programs that change the layout of a page, add or remove new functionality and content, or automate actions.

Does Tampermonkey use JavaScript?

Tampermonkey is a donationware userscript manager that is available as a browser extension. This software enables the user to add and use userscripts, which are JavaScript programs that can be used to modify web pages.

Where are Greasemonkey scripts stored?

They're stored in an IndexedDB ( https://github.com/greasemonkey/greasemonkey/blob/master/src/bg/user-script-registry.js#L287 ) which is a format with very little (AFAIK?) tooling. (Because there's very few options for persistence for a WebExtension.)


1 Answers

Does Greasemonkey insert the wrapper into the source JavaScript code or add it as any event handler such as window.onload?

GM listens to DOMContentLoaded event (basically DOM Ready) here. Then wraps the userscript code and inserts that into a sandbox, here.

like image 77
erikvold Avatar answered Oct 31 '22 21:10

erikvold