Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intercepting JavaScript before going to JavaScript Engine in Mozilla Firefox

I want to develop an extension which works on scripts coming from HTTP response. I know that whole HTML code first goes to rendering engine inside browser where it is parsed to create a DOM tree. Any script embedded inside is passed to the JavaScript Engine.(Correct me if I am wrong. :) ) So I wanted to intercept the JavaScript code before it is sent to the JavaScript Engine in order to modify them accordingly.

Are there any APIs for Mozilla Firefox which would allow me to do this? How can I do it?

like image 445
Naman Avatar asked Jan 28 '26 08:01

Naman


1 Answers

while doing some stuff i stumbled across this: https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/NsITraceableChannel?redirectlocale=en-US&redirectslug=NsITraceableChannel

this allows you to modify stuff before it is parsed. see this topic here: http://forums.mozillazine.org/viewtopic.php?f=19&t=2800541

here is a working example of getting the content before it is shown to user. it doesnt change it though, thats what im asking in the mozillazine topic. the writeBytes should modify it, once you figure it out please share as im interested as well https://github.com/Noitidart/demo-nsITraceableChannel

like image 141
Noitidart Avatar answered Jan 30 '26 21:01

Noitidart