简体   繁体   中英

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 ?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM