views:

27

answers:

2

I need a way to process HTML before it's actually loaded and parsed by Mozilla. Is there any content listener that I can use in my Firefox extension?

A: 

Do you mean something like greasemonkey? Sorry, I don't know enough about Firefox extensions. The Greasemonkey website is blocked here in China and my VPN does not work at the moment, but maybe they are open source. Then you can see what they do, if writing a greasemonkey skript is not what you want.

erikb
Greasmonkey starts processing DOM model after "DOMContentLoaded" event is triggered. What I need is to intercept HTML content **before** Mozilla loads and parses it. But you're right, I need something similar to this extension, with the exception that it works at earlier stage.
spektom
A: 

Add an Event Listener to the gBrowser global object, making sure to set usecapture to true. You could also intercept the response.

Fábio
Does "onload" event happen before Mozilla reads contents?
spektom
BTW, nsIHttpChannel only allows to modify HTTP headers, not content.
spektom
The Http Channel also implements other interfaces, such as nsIRequest, which might do what you want. This took me a long time to realize.
MatrixFrog