Getting content of page after http request.

I want to create a special tracker, which would help me in my daily work(it=
'd track my chats with customer and store it & make statistics), so I decid=
ed to make Mozilla Firefox add-on to make it simpler. I managed to do getti=
ng URL myself, but the problem is, that even with using this tutorial:
http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-ht=
tp-traffic/
I can't get content of page, which is loaded by the browser(which by the wa=
y is json code, which will be parsed & sent to database). I do not want to =
modify text response given by the HTTP Response, just see it & alert it. My=
 code is:
[code]
    var ObserverTest =3D {

    register: function() {
        var observerService =3D Components.classes["@mozilla.org/observer-s=
ervice;1"]
            .getService(Components.interfaces.nsIObserverService);
        observerService.addObserver(ObserverTest, "http-on-modify-request",=
 false);
        observerService.addObserver(ObserverTest, "http-on-examine-response=
", false)
    },

    observe: function(subject, topic, data) {
        var httpChannel =3D subject.QueryInterface(Components.interfaces.ns=
IHttpChannel);
        switch (topic) {
            case 'http-on-modify-request':
                // every 5 seconds and immediately when user becomes active
                //alert(httpChannel.originalURI.spec); //it gets url which =
I send request to, is ok, no need of ingeration
                //alert('request?');=20
            break;
            case 'http-on-examine-response':
            //alert(httpChannel.responseText);
                //alert()
                //alert('responde!'); //there I want to alert content(text =
responde) which is given by pages

            break;
        }
    },

    unregister: function() {
        var observerService =3D Components.classes["@mozilla.org/observer-s=
ervice;1"]
            .getService(Components.interfaces.nsIObserverService);
        observerService.removeObserver(ObserverTest, "http-on-modify-reques=
t");
        observerService.removeObserver(ObserverTest, "http-on-examine-respo=
nse");
    },
   =20
    QueryInterface : function (aIID)
    {
        if (aIID.equals(Ci.nsIObserver) ||
            aIID.equals(Ci.nsISupports))
        {
            return this;
        }

        throw Components.results.NS_NOINTERFACE;

    }
    }

    window.addEventListener("load", ObserverTest.register, false);
    window.addEventListener("unload", ObserverTest.unregister, false);
[/code]
Ofc. it still needs filtrating, but I can handle it myself and just need to=
 print content.

#extdev
So, I've been to extdev, where a nice guy called Mook_as provided me half-d=
one solution of my problem, unfortunatly I have no idea what to do next. Hi=
s version(whis isnt done to work yet) you can see there:
http://pastebin.mozilla.org/2225956
0
Magic
3/18/2013 7:15:03 PM
mozilla.dev.extensions 5694 articles. 0 followers. Post Follow

9 Replies
2077 Views

Similar Articles

[PageSpeed] 16

This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
------enig2NBBTVMCFNQPLPMNWDOON
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

If you look back to the article, you could create the `TracingListener' i=
nside the `http-on-examine-response'-case. I remember that article from w=
orking on my own addon:

Creating the listener for `http-on-examine-response':

    https://github.com/kimabrandt/yarip/blob/yarip-0.3.3/modules/observer=
=2Ejsm#L243

In my case I collect all `receivedData' when the listener does `onDataAva=
ilable' and manipulate the overall `responseSource' when the listener doe=
s `onStopRequest':

    https://github.com/kimabrandt/yarip/blob/yarip-0.3.3/modules/stream.j=
sm#L35

I hope this is helpful.

/Kim

On 2013-03-18 20:15, Magic wrote:
> I want to create a special tracker, which would help me in my daily wor=
k(it'd track my chats with customer and store it & make statistics), so I=
 decided to make Mozilla Firefox add-on to make it simpler. I managed to =
do getting URL myself, but the problem is, that even with using this tuto=
rial:
> http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercep=
t-http-traffic/
> I can't get content of page, which is loaded by the browser(which by th=
e way is json code, which will be parsed & sent to database). I do not wa=
nt to modify text response given by the HTTP Response, just see it & aler=
t it. My code is:
> [code]
>     var ObserverTest =3D {
>=20
>     register: function() {
>         var observerService =3D Components.classes["@mozilla.org/observ=
er-service;1"]
>             .getService(Components.interfaces.nsIObserverService);
>         observerService.addObserver(ObserverTest, "http-on-modify-reque=
st", false);
>         observerService.addObserver(ObserverTest, "http-on-examine-resp=
onse", false)
>     },
>=20
>     observe: function(subject, topic, data) {
>         var httpChannel =3D subject.QueryInterface(Components.interface=
s.nsIHttpChannel);
>         switch (topic) {
>             case 'http-on-modify-request':
>                 // every 5 seconds and immediately when user becomes ac=
tive
>                 //alert(httpChannel.originalURI.spec); //it gets url wh=
ich I send request to, is ok, no need of ingeration
>                 //alert('request?');=20
>             break;
>             case 'http-on-examine-response':
>             //alert(httpChannel.responseText);
>                 //alert()
>                 //alert('responde!'); //there I want to alert content(t=
ext responde) which is given by pages
>=20
>             break;
>         }
>     },
>=20
>     unregister: function() {
>         var observerService =3D Components.classes["@mozilla.org/observ=
er-service;1"]
>             .getService(Components.interfaces.nsIObserverService);
>         observerService.removeObserver(ObserverTest, "http-on-modify-re=
quest");
>         observerService.removeObserver(ObserverTest, "http-on-examine-r=
esponse");
>     },
>    =20
>     QueryInterface : function (aIID)
>     {
>         if (aIID.equals(Ci.nsIObserver) ||
>             aIID.equals(Ci.nsISupports))
>         {
>             return this;
>         }
>=20
>         throw Components.results.NS_NOINTERFACE;
>=20
>     }
>     }
>=20
>     window.addEventListener("load", ObserverTest.register, false);
>     window.addEventListener("unload", ObserverTest.unregister, false);
> [/code]
> Ofc. it still needs filtrating, but I can handle it myself and just nee=
d to print content.
>=20
> #extdev
> So, I've been to extdev, where a nice guy called Mook_as provided me ha=
lf-done solution of my problem, unfortunatly I have no idea what to do ne=
xt. His version(whis isnt done to work yet) you can see there:
> http://pastebin.mozilla.org/2225956
> _______________________________________________
> dev-extensions mailing list
> dev-extensions@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-extensions


------enig2NBBTVMCFNQPLPMNWDOON
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRR37UAAoJEN9xx3Fpwq25cRAQANVhS3LnjhYKSzx1bZ69EfMf
aBjRhKdfrraSRlt0G8A357z1C6RMwavrktqbBrLH7cy0EyrIfxSOLq7vbJIcwYay
WigvecYhKxSDCole8af0MekmVF66mSfWbsRkzcdtG5GJ74SUyR8pfd/JhR+/U7PU
Fs/8kp0S7Oi1ucvuJXDJopmw6R2oGxHeB9GKr8QoxFfWal4vixj+tZPeWX5DJ8pv
aXbHgt51olm2y9EB2CST7hFPwm+dYePHBLSidTbxoOrChins6WqFU50I+JjGPIUa
L35ed8N1zUePDvKFj+8YXuo2A9R/Rra2tDYWroLZ3jcAqHTf3LwgAm6AOW8Rr5by
XsZA7yWEdYnfFcO87VdgmyvD6FxCFqU6l2iCUO/nPTFRWnaNIJxzI/sc04H0yCeJ
256ZjLgYEVkI+gye4eWRdza1ve1tns9DF9O2qGm+9pdhPvx4b/WLbH9eSJMsvL0F
5vvspctDNC8FkAAwrBv1ldugKgT8ppy5k82JcbuDi6pIpgCOtnjNeum5nuVJdXR1
y2vojxLvRMJOErGgcuw/TtG6r5oYsEPZXk8xfbBLiiXLrX5NFUrYPoeMC8Ij6Uj2
3H1hl2H3Kn8vF8ivzOhJphW6NnkjI6BsVIGSWoSFIs+IuTMJzhVi9SL9zbM5p17P
IrMO3SjNHsJpbp0JrHzJ
=IxzR
-----END PGP SIGNATURE-----

------enig2NBBTVMCFNQPLPMNWDOON--
0
Kim
3/18/2013 8:53:32 PM
W dniu poniedzia=C5=82ek, 18 marca 2013 20:15:03 UTC+1 u=C5=BCytkownik Magi=
c napisa=C5=82:
> I want to create a special tracker, which would help me in my daily work(=
it'd track my chats with customer and store it & make statistics), so I dec=
ided to make Mozilla Firefox add-on to make it simpler. I managed to do get=
ting URL myself, but the problem is, that even with using this tutorial:
>=20
> http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-=
http-traffic/
>=20
> I can't get content of page, which is loaded by the browser(which by the =
way is json code, which will be parsed & sent to database). I do not want t=
o modify text response given by the HTTP Response, just see it & alert it. =
My code is:
>=20
> [code]
>=20
>     var ObserverTest =3D {
>=20
>=20
>=20
>     register: function() {
>=20
>         var observerService =3D Components.classes["@mozilla.org/observer=
-service;1"]
>=20
>             .getService(Components.interfaces.nsIObserverService);
>=20
>         observerService.addObserver(ObserverTest, "http-on-modify-request=
", false);
>=20
>         observerService.addObserver(ObserverTest, "http-on-examine-respon=
se", false)
>=20
>     },
>=20
>=20
>=20
>     observe: function(subject, topic, data) {
>=20
>         var httpChannel =3D subject.QueryInterface(Components.interfaces.=
nsIHttpChannel);
>=20
>         switch (topic) {
>=20
>             case 'http-on-modify-request':
>=20
>                 // every 5 seconds and immediately when user becomes acti=
ve
>=20
>                 //alert(httpChannel.originalURI.spec); //it gets url whic=
h I send request to, is ok, no need of ingeration
>=20
>                 //alert('request?');=20
>=20
>             break;
>=20
>             case 'http-on-examine-response':
>=20
>             //alert(httpChannel.responseText);
>=20
>                 //alert()
>=20
>                 //alert('responde!'); //there I want to alert content(tex=
t responde) which is given by pages
>=20
>=20
>=20
>             break;
>=20
>         }
>=20
>     },
>=20
>=20
>=20
>     unregister: function() {
>=20
>         var observerService =3D Components.classes["@mozilla.org/observer=
-service;1"]
>=20
>             .getService(Components.interfaces.nsIObserverService);
>=20
>         observerService.removeObserver(ObserverTest, "http-on-modify-requ=
est");
>=20
>         observerService.removeObserver(ObserverTest, "http-on-examine-res=
ponse");
>=20
>     },
>=20
>    =20
>=20
>     QueryInterface : function (aIID)
>=20
>     {
>=20
>         if (aIID.equals(Ci.nsIObserver) ||
>=20
>             aIID.equals(Ci.nsISupports))
>=20
>         {
>=20
>             return this;
>=20
>         }
>=20
>=20
>=20
>         throw Components.results.NS_NOINTERFACE;
>=20
>=20
>=20
>     }
>=20
>     }
>=20
>=20
>=20
>     window.addEventListener("load", ObserverTest.register, false);
>=20
>     window.addEventListener("unload", ObserverTest.unregister, false);
>=20
> [/code]
>=20
> Ofc. it still needs filtrating, but I can handle it myself and just need =
to print content.
>=20
>=20
>=20
> #extdev
>=20
> So, I've been to extdev, where a nice guy called Mook_as provided me half=
-done solution of my problem, unfortunatly I have no idea what to do next. =
His version(whis isnt done to work yet) you can see there:
>=20
> http://pastebin.mozilla.org/2225956

Thanks for you help!:) It helped me a little, as I started to understand th=
e point of that listener thing, so I decided to use a little of your code, =
but I guess I made something wrong as it's not alerting context of page:
http://pastebin.com/XfZ0THHu
0
Magic
3/18/2013 9:37:18 PM
Whoops, the seconds link should be the `..ResponseStreamListener':

    https://github.com/kimabrandt/yarip/blob/yarip-0.3.3/modules/stream.jsm#L84

/Kim

On 2013-03-18 21:53, Kim A. Brandt wrote:
> If you look back to the article, you could create the `TracingListener' inside the `http-on-examine-response'-case. I remember that article from working on my own addon:
> 
> Creating the listener for `http-on-examine-response':
> 
>     https://github.com/kimabrandt/yarip/blob/yarip-0.3.3/modules/observer.jsm#L243
> 
> In my case I collect all `receivedData' when the listener does `onDataAvailable' and manipulate the overall `responseSource' when the listener does `onStopRequest':
> 
>     https://github.com/kimabrandt/yarip/blob/yarip-0.3.3/modules/stream.jsm#L35
> 
> I hope this is helpful.
> 
> /Kim
>...
0
Kim
3/18/2013 10:00:26 PM
Whoops, the seconds link should be the `..ResponseStreamListener':

    https://github.com/kimabrandt/yarip/blob/yarip-0.3.3/modules/stream.jsm#L84

/Kim

On 2013-03-18 21:53, Kim A. Brandt wrote:
> If you look back to the article, you could create the `TracingListener' inside the `http-on-examine-response'-case. I remember that article from working on my own addon:
> 
> Creating the listener for `http-on-examine-response':
> 
>     https://github.com/kimabrandt/yarip/blob/yarip-0.3.3/modules/observer.jsm#L243
> 
> In my case I collect all `receivedData' when the listener does `onDataAvailable' and manipulate the overall `responseSource' when the listener does `onStopRequest':
> 
>     https://github.com/kimabrandt/yarip/blob/yarip-0.3.3/modules/stream.jsm#L35
> 
> I hope this is helpful.
> 
> /Kim
>...
0
Kim
3/18/2013 10:00:26 PM
From your code:

    ...
    case 'http-on-examine-response':
    var httpChannel = subject.QueryInterface(Components.interfaces.nsITraceableChannel);
    alert(httpChannel.getResponseHeader("Content"));
    new StreamListener(subject);
    //alert(httpChannel.responseText);
        //alert()
        //alert('responde!');
    break;
    ...

`alert' is probably not going to work. Try to `dump()' or send the `responseSource' to the `Error Console'[1] from within the `onStopRequest'-function of the listener and go from there.

/Kim

[1] Components.utils.reportError | MDN - https://developer.mozilla.org/en-US/docs/Components.utils.reportError

On 2013-03-18 22:37, Magic wrote:
> W dniu poniedziałek, 18 marca 2013 20:15:03 UTC+1 użytkownik Magic napisał:
>> I want to create a special tracker, which would help me in my daily work(it'd track my chats with customer and store it & make statistics), so I decided to make Mozilla Firefox add-on to make it simpler. I managed to do getting URL myself, but the problem is, that even with using this tutorial:
>>
>> http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-http-traffic/
>>
>> I can't get content of page, which is loaded by the browser(which by the way is json code, which will be parsed & sent to database). I do not want to modify text response given by the HTTP Response, just see it & alert it. My code is:
>>
>> [code]
>>
>>     var ObserverTest = {
>>
>>
>>
>>     register: function() {
>>
>>         var observerService = Components.classes["@mozilla.org/observer-service;1"]
>>
>>             .getService(Components.interfaces.nsIObserverService);
>>
>>         observerService.addObserver(ObserverTest, "http-on-modify-request", false);
>>
>>         observerService.addObserver(ObserverTest, "http-on-examine-response", false)
>>
>>     },
>>
>>
>>
>>     observe: function(subject, topic, data) {
>>
>>         var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
>>
>>         switch (topic) {
>>
>>             case 'http-on-modify-request':
>>
>>                 // every 5 seconds and immediately when user becomes active
>>
>>                 //alert(httpChannel.originalURI.spec); //it gets url which I send request to, is ok, no need of ingeration
>>
>>                 //alert('request?'); 
>>
>>             break;
>>
>>             case 'http-on-examine-response':
>>
>>             //alert(httpChannel.responseText);
>>
>>                 //alert()
>>
>>                 //alert('responde!'); //there I want to alert content(text responde) which is given by pages
>>
>>
>>
>>             break;
>>
>>         }
>>
>>     },
>>
>>
>>
>>     unregister: function() {
>>
>>         var observerService = Components.classes["@mozilla.org/observer-service;1"]
>>
>>             .getService(Components.interfaces.nsIObserverService);
>>
>>         observerService.removeObserver(ObserverTest, "http-on-modify-request");
>>
>>         observerService.removeObserver(ObserverTest, "http-on-examine-response");
>>
>>     },
>>
>>     
>>
>>     QueryInterface : function (aIID)
>>
>>     {
>>
>>         if (aIID.equals(Ci.nsIObserver) ||
>>
>>             aIID.equals(Ci.nsISupports))
>>
>>         {
>>
>>             return this;
>>
>>         }
>>
>>
>>
>>         throw Components.results.NS_NOINTERFACE;
>>
>>
>>
>>     }
>>
>>     }
>>
>>
>>
>>     window.addEventListener("load", ObserverTest.register, false);
>>
>>     window.addEventListener("unload", ObserverTest.unregister, false);
>>
>> [/code]
>>
>> Ofc. it still needs filtrating, but I can handle it myself and just need to print content.
>>
>>
>>
>> #extdev
>>
>> So, I've been to extdev, where a nice guy called Mook_as provided me half-done solution of my problem, unfortunatly I have no idea what to do next. His version(whis isnt done to work yet) you can see there:
>>
>> http://pastebin.mozilla.org/2225956
> 
> Thanks for you help!:) It helped me a little, as I started to understand the point of that listener thing, so I decided to use a little of your code, but I guess I made something wrong as it's not alerting context of page:
> http://pastebin.com/XfZ0THHu
> 

0
Kim
3/18/2013 10:06:45 PM
W dniu poniedzia=C5=82ek, 18 marca 2013 20:15:03 UTC+1 u=C5=BCytkownik Magi=
c napisa=C5=82:
> I want to create a special tracker, which would help me in my daily work(=
it'd track my chats with customer and store it & make statistics), so I dec=
ided to make Mozilla Firefox add-on to make it simpler. I managed to do get=
ting URL myself, but the problem is, that even with using this tutorial:
>=20
> http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-=
http-traffic/
>=20
> I can't get content of page, which is loaded by the browser(which by the =
way is json code, which will be parsed & sent to database). I do not want t=
o modify text response given by the HTTP Response, just see it & alert it. =
My code is:
>=20
> [code]
>=20
>     var ObserverTest =3D {
>=20
>=20
>=20
>     register: function() {
>=20
>         var observerService =3D Components.classes["@mozilla.org/observer=
-service;1"]
>=20
>             .getService(Components.interfaces.nsIObserverService);
>=20
>         observerService.addObserver(ObserverTest, "http-on-modify-request=
", false);
>=20
>         observerService.addObserver(ObserverTest, "http-on-examine-respon=
se", false)
>=20
>     },
>=20
>=20
>=20
>     observe: function(subject, topic, data) {
>=20
>         var httpChannel =3D subject.QueryInterface(Components.interfaces.=
nsIHttpChannel);
>=20
>         switch (topic) {
>=20
>             case 'http-on-modify-request':
>=20
>                 // every 5 seconds and immediately when user becomes acti=
ve
>=20
>                 //alert(httpChannel.originalURI.spec); //it gets url whic=
h I send request to, is ok, no need of ingeration
>=20
>                 //alert('request?');=20
>=20
>             break;
>=20
>             case 'http-on-examine-response':
>=20
>             //alert(httpChannel.responseText);
>=20
>                 //alert()
>=20
>                 //alert('responde!'); //there I want to alert content(tex=
t responde) which is given by pages
>=20
>=20
>=20
>             break;
>=20
>         }
>=20
>     },
>=20
>=20
>=20
>     unregister: function() {
>=20
>         var observerService =3D Components.classes["@mozilla.org/observer=
-service;1"]
>=20
>             .getService(Components.interfaces.nsIObserverService);
>=20
>         observerService.removeObserver(ObserverTest, "http-on-modify-requ=
est");
>=20
>         observerService.removeObserver(ObserverTest, "http-on-examine-res=
ponse");
>=20
>     },
>=20
>    =20
>=20
>     QueryInterface : function (aIID)
>=20
>     {
>=20
>         if (aIID.equals(Ci.nsIObserver) ||
>=20
>             aIID.equals(Ci.nsISupports))
>=20
>         {
>=20
>             return this;
>=20
>         }
>=20
>=20
>=20
>         throw Components.results.NS_NOINTERFACE;
>=20
>=20
>=20
>     }
>=20
>     }
>=20
>=20
>=20
>     window.addEventListener("load", ObserverTest.register, false);
>=20
>     window.addEventListener("unload", ObserverTest.unregister, false);
>=20
> [/code]
>=20
> Ofc. it still needs filtrating, but I can handle it myself and just need =
to print content.
>=20
>=20
>=20
> #extdev
>=20
> So, I've been to extdev, where a nice guy called Mook_as provided me half=
-done solution of my problem, unfortunatly I have no idea what to do next. =
His version(whis isnt done to work yet) you can see there:
>=20
> http://pastebin.mozilla.org/2225956

Ok, I've got something like it:
http://pastebin.com/MpiuK2RH

I've tried both dump() and alert(), but unfortunatly they do not work. I wo=
nder how can I look at it in some other way(if the script is ok and it's ju=
st case of good function) [Line: 60]
0
Magic
3/18/2013 10:18:06 PM
Is there any way to debug it actually? I dont get any errors and that's killing me :P
0
Magic
3/18/2013 10:28:55 PM
On 03/18/2013 06:28 PM, Magic wrote:
> Is there any way to debug it actually? I dont get any errors and that's killing me :P
>

Components.utils.reportError("fooo") and look in the global error console.

Cheers,
Josh
0
Josh
3/19/2013 4:21:34 AM
Thanks guys, it works perfectly!:) Now manipulation of the results and plugin is done! <3 (or Brasilian s2)
0
Magic
3/19/2013 2:49:58 PM
Reply:

Web resources about - Getting content of page after http request. - mozilla.dev.extensions

Ted Cruz Makes a Big Leap in Iowa, Poll Says
New York Times Ted Cruz Makes a Big Leap in Iowa, Poll Says New York Times Ted Cruz's long-anticipated Iowa surge came a step closer on Tuesday ...

For J.J. Abrams, building a game is a learning experience
J.J. Abrams cites a long list of gaming loves. He played those early Infocom text adventures and lined up to drop quarters into Asteroids "coin-op" ...

U.S. retailers hunt for cyber attacks after malware warning leading into holiday shopping season
BOSTON (By Jim Finkle, Reuters) – U.S. retailers are hunting for evidence of new breaches leading into the holiday shopping season after a cyber ...

I Bet This Guy Could Sniff Out Some Great Black Friday Deals
Submitted by: (via ZooBorns ) Tagged: sengis , cute , black friday , Video Share on Facebook

California city to pay $4.9 million over fatal beating of homeless man
The city of Fullerton, California, agreed on Monday to pay $4.9 million to settle a lawsuit brought by the father of a homeless man beaten to ...

Popular mobile payment apps leave consumers and businesses exposed
It's likely that this year's holiday season will mark the first time that online purchases made on mobile devices will overtake those on desktop ...

NATO calls 'extraordinary meeting' after Turkey downs Russian jet
NATO allies will hold an "extraordinary" meeting Tuesday at Ankara's request to discuss Turkey's shooting down of a Russian fighter jet along ...

Own your drone: the US is one step closer to drone registration
A new report for the US Federal Aviation Administration (FAA) has recommended that drones weighing over 250g should be officially registered ...


Dell responds to concerns over certificate vulnerability
Security problems are certainly nothing new, vulnerabilities seem to crop up just about everywhere. We've seen countless ones from software makers ...

Resources last updated: 11/24/2015 1:01:36 PM