I'm looking at various options I have to enhance my browsing experience. I found a ton of userscripts available at userscripts. But, I also was reading up on Google Chrome extensions (which seem very similar to userscripts).
I'm wondering if there is any advantages to using a userscript vs. an extension? The one thing I can't seem to get working is using either of these techniques to inject scripts into the DOM so that I can have my javascript code access the pages' javascript methods. It works fine as a single userscript install, but when I attempted to convert that userscript into an extension, it did not seem to work. Though, I wasn't sure if I did something wrong or if it can't work at all.
The main reason I ask is because after I started working on my own userscript I ran into the issue that the script file grew very large and repetitive to other scripts. Chrome doesn't support the "@require" option so I can't organize my "mon" code that way, which is what lead me to think I should be looking at extensions instead.
So, is it possible to use "Script Injection" or "Location Hack" in an extension so that my javascript can execute on the DOM and access the other javascript?
I'm looking at various options I have to enhance my browsing experience. I found a ton of userscripts available at userscripts. But, I also was reading up on Google Chrome extensions (which seem very similar to userscripts).
I'm wondering if there is any advantages to using a userscript vs. an extension? The one thing I can't seem to get working is using either of these techniques to inject scripts into the DOM so that I can have my javascript code access the pages' javascript methods. It works fine as a single userscript install, but when I attempted to convert that userscript into an extension, it did not seem to work. Though, I wasn't sure if I did something wrong or if it can't work at all.
The main reason I ask is because after I started working on my own userscript I ran into the issue that the script file grew very large and repetitive to other scripts. Chrome doesn't support the "@require" option so I can't organize my "mon" code that way, which is what lead me to think I should be looking at extensions instead.
So, is it possible to use "Script Injection" or "Location Hack" in an extension so that my javascript can execute on the DOM and access the other javascript?
Share Improve this question edited May 23, 2017 at 12:15 CommunityBot 11 silver badge asked Jun 4, 2012 at 14:04 myermianmyermian 32.5k26 gold badges132 silver badges221 bronze badges2 Answers
Reset to default 5To answer your first question: UserScripts are single files which can not request access to Chrome API's, such as bookmarks, cross-domain XMLHttpRequest etc. Chrome extensions are multiple zipped-up files which do not have these limitations.
As for your second question, I suggest you to read How can I mimic Greasemonkey/Firefox's unsafeWindow functionality in Chrome?.
See here for the explanation of an "Isolated World" for a Chrome Extension Content Script. You can access the websites DOM, but not Variables/Functions in another Script...
http://code.google./chrome/extensions/content_scripts.html#execution-environment