[Greasemonkey] How to specify script injection time

Steve Krulewitz shooz at mm.st
Sun Jul 17 13:23:03 EDT 2005


Bill Donnelly wrote:
> If you're going to that much trouble, then why not just
> put a few lines of code in the location where it starts
> injecting scripts before signalling DOM load to first
> inject Gm scripts, or modify the script injection code
> to inject Gm scripts first? Simple is better and has
> less chance of causing bugs and other malfunctions.
> 

If you saying that rather than injecting the entire script into the byte
stream, you should just inject a small script that can call an exposed
GM function (e.g. <script>GM_init();</script>) then I agree, that is a
good idea.

I happen to be working on something that can be easily applied to test
this type of injection without monkeying with mozilla internals.  It is
a simple HTTP proxy written in perl that adds
<script>alert("hello");</script> to the beginning of every text/html
response, and just alert("hello"); to the top of every text/javascript
response:

http://skrul.com/greasemonkey/gmproxy.plx

Some light testing shows that gmaps works fine, and gmail seems to work
fine except for this error that shows up on the console:

Error: top.main has no properties
Source File:
http://mail.google.com/mail/?view=page&name=js&ver=ac3b53ae970e1fe
Line: 60

This method also allows GM to inject code into javascript requests
rather than just stuff that gets parsed into a DOM.  This may open up
more monkeying possibilities in the future :)

cheers,
-steve


More information about the Greasemonkey mailing list