[Greasemonkey] How to specify script injection time
shooz at mm.st
Sat Jul 16 11:40:43 EDT 2005
Bill Donnelly wrote:
> So what we have is probably the best we'll ever get.
> Unless you can convince the Firefox team to add in some
> special code, but I would bet the odds of that are
> somewhere between slim and none.
Pardon me if this has been suggested before, but might it be possible to
inject user scripts into the byte stream of a loading page? Looking at
It seems like there might be a few possibilities, the most obvious would
be to replace the stock nsHTTPHandler with a custom version. Under
normal circumstances, this custom http handler would just forward calls
to the original http handler. However, if the URL is matched by a GM
script, the custom http handler kicks in. From the diagram, I would
guess that the custom http handler would produce a custom nsIChannel
that can inject the script into the proper point of the byte stream.
Then the injected SCRIPT block could be removed later in the request
Some amount of care would have to be taken to make sure the scripts are
injected in the proper place, as well as make sure the injection only
happens for http request that are bound for web page rendering (don't
inject for image request, don't inject for XHR requests, etc).
More information about the Greasemonkey