<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Howto: XHR Listening by a Firefox Addon</title>
	<atom:link href="http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/</link>
	<description></description>
	<lastBuildDate>Tue, 06 Jul 2010 22:13:58 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Andy E</title>
		<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/comment-page-1/#comment-1237</link>
		<dc:creator>Andy E</dc:creator>
		<pubDate>Tue, 06 Jul 2010 22:13:58 +0000</pubDate>
		<guid isPermaLink="false">http://ashita.org/?p=307#comment-1237</guid>
		<description>@Johnathan,

well you do have a point here, but ... to get rid of over-eager javascripts I MUST modify the document before the browser sees it (if this was what you mean, that is). The JS interpreters embedded in various browsers will always *pre-process* all inline JS, so any changes after loading the full document will get dismissed. (Trust me, I had to go through all this first to realize that my attempts were fruitless :))</description>
		<content:encoded><![CDATA[<p>@Johnathan,</p>
<p>well you do have a point here, but &#8230; to get rid of over-eager javascripts I MUST modify the document before the browser sees it (if this was what you mean, that is). The JS interpreters embedded in various browsers will always *pre-process* all inline JS, so any changes after loading the full document will get dismissed. (Trust me, I had to go through all this first to realize that my attempts were fruitless :))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Fingland</title>
		<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/comment-page-1/#comment-1236</link>
		<dc:creator>Jonathan Fingland</dc:creator>
		<pubDate>Fri, 02 Jul 2010 19:46:49 +0000</pubDate>
		<guid isPermaLink="false">http://ashita.org/?p=307#comment-1236</guid>
		<description>@Andy, 


The binary input stream&#039;s readBytes() method is just a string of bytes... you *could* parse it--and manipulate it--but there are too many potential problems. 

Don&#039;t try to parse until the download is complete.  Let&#039;s say the stream comes in two parts... You can&#039;t create a parse-able document from that. You&#039;ll have unclosed tags, parts of multi-byte characters, etc.

By the way... in all honesty, it&#039;s probably better to modify the document after it has loaded. Delaying document loading is definitely unexpected behaviour.</description>
		<content:encoded><![CDATA[<p>@Andy, </p>
<p>The binary input stream&#8217;s readBytes() method is just a string of bytes&#8230; you *could* parse it&#8211;and manipulate it&#8211;but there are too many potential problems. </p>
<p>Don&#8217;t try to parse until the download is complete.  Let&#8217;s say the stream comes in two parts&#8230; You can&#8217;t create a parse-able document from that. You&#8217;ll have unclosed tags, parts of multi-byte characters, etc.</p>
<p>By the way&#8230; in all honesty, it&#8217;s probably better to modify the document after it has loaded. Delaying document loading is definitely unexpected behaviour.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy E</title>
		<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/comment-page-1/#comment-1234</link>
		<dc:creator>Andy E</dc:creator>
		<pubDate>Thu, 01 Jul 2010 12:11:24 +0000</pubDate>
		<guid isPermaLink="false">http://ashita.org/?p=307#comment-1234</guid>
		<description>@ Jonathan,

thanks for your reply, and your sample code. However, you&#039;re one step ahead :)

I&#039;m still in onDataAvailable():
var data = binaryInputStream.readBytes(count);

At first, I&#039;ll need the step how to get the binaryInputStream to something better parseable.</description>
		<content:encoded><![CDATA[<p>@ Jonathan,</p>
<p>thanks for your reply, and your sample code. However, you&#8217;re one step ahead :)</p>
<p>I&#8217;m still in onDataAvailable():<br />
var data = binaryInputStream.readBytes(count);</p>
<p>At first, I&#8217;ll need the step how to get the binaryInputStream to something better parseable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Fingland</title>
		<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/comment-page-1/#comment-1233</link>
		<dc:creator>Jonathan Fingland</dc:creator>
		<pubDate>Wed, 30 Jun 2010 16:42:36 +0000</pubDate>
		<guid isPermaLink="false">http://ashita.org/?p=307#comment-1233</guid>
		<description>@Andy,

What you *could* try doing is not passing things on down the listener chain until the very end. Do your processing on the completed string/page and then pass the modified version on to the other listeners.

To perform normal DOM methods, you can load the content into a virtual iframe:

              function createDoc (htmlText) {
			_iframe.docShell.allowJavascript = false;
			_iframe.docShell.allowAuth = false;
			_iframe.docShell.allowPlugins = false;
			_iframe.docShell.allowMetaRedirects = false;
			_iframe.docShell.allowSubframes = false;
			_iframe.docShell.allowImages = false;
			
			var doc = _iframe.contentDocument; 
			var strip = /&lt;html[\s\S]*?&gt;([\s\S]*?)&lt;\/html&gt;/i;
			if (strip.test(htmlText)) {
				doc.getElementsByTagName(&quot;html&quot;)[0].innerHTML = strip.exec(htmlText)[1];
			}
			
			return doc;
		}

And then just get the content back out again when you want to pass it on to the next listener</description>
		<content:encoded><![CDATA[<p>@Andy,</p>
<p>What you *could* try doing is not passing things on down the listener chain until the very end. Do your processing on the completed string/page and then pass the modified version on to the other listeners.</p>
<p>To perform normal DOM methods, you can load the content into a virtual iframe:</p>
<p>              function createDoc (htmlText) {<br />
			_iframe.docShell.allowJavascript = false;<br />
			_iframe.docShell.allowAuth = false;<br />
			_iframe.docShell.allowPlugins = false;<br />
			_iframe.docShell.allowMetaRedirects = false;<br />
			_iframe.docShell.allowSubframes = false;<br />
			_iframe.docShell.allowImages = false;</p>
<p>			var doc = _iframe.contentDocument;<br />
			var strip = /<html [\s\S]*?>([\s\S]*?)< \/html>/i;<br />
			if (strip.test(htmlText)) {<br />
				doc.getElementsByTagName(&#8221;html&#8221;)[0].innerHTML = strip.exec(htmlText)[1];<br />
			}</p>
<p>			return doc;<br />
		}</p>
<p>And then just get the content back out again when you want to pass it on to the next listener</html></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy E</title>
		<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/comment-page-1/#comment-1232</link>
		<dc:creator>Andy E</dc:creator>
		<pubDate>Wed, 30 Jun 2010 03:37:44 +0000</pubDate>
		<guid isPermaLink="false">http://ashita.org/?p=307#comment-1232</guid>
		<description>Hi,

this is a great site. I have to bookmark this one now as Honza has closed the comments section (for no obvious reason, whatsoever!) 
Well then.

I wonder why you need a BINARY input stream for all that?
Supposed I want to use this code as a basis to transform a web page &quot;on the fly&quot; before the browser can get hold of it, e. g. to remove over-eager javascripts or even only a few JS _lines_.

Supposed too that the stream is nothing but HTML+JS, it would be great to be able to use a DOM function like getElementsByTagName() to get some nodes *before* the browser can do anything with the page.
AFAIK this is not possible with a binary input stream.

So am I doomed to use the BIS or can I also use a sort of &quot;character input stream&quot;?</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>this is a great site. I have to bookmark this one now as Honza has closed the comments section (for no obvious reason, whatsoever!)<br />
Well then.</p>
<p>I wonder why you need a BINARY input stream for all that?<br />
Supposed I want to use this code as a basis to transform a web page &#8220;on the fly&#8221; before the browser can get hold of it, e. g. to remove over-eager javascripts or even only a few JS _lines_.</p>
<p>Supposed too that the stream is nothing but HTML+JS, it would be great to be able to use a DOM function like getElementsByTagName() to get some nodes *before* the browser can do anything with the page.<br />
AFAIK this is not possible with a binary input stream.</p>
<p>So am I doomed to use the BIS or can I also use a sort of &#8220;character input stream&#8221;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: designer mode</title>
		<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/comment-page-1/#comment-1231</link>
		<dc:creator>designer mode</dc:creator>
		<pubDate>Sun, 27 Jun 2010 01:20:58 +0000</pubDate>
		<guid isPermaLink="false">http://ashita.org/?p=307#comment-1231</guid>
		<description>This is exactly what I was looking for!</description>
		<content:encoded><![CDATA[<p>This is exactly what I was looking for!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Fingland</title>
		<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/comment-page-1/#comment-1125</link>
		<dc:creator>Jonathan Fingland</dc:creator>
		<pubDate>Thu, 22 Apr 2010 16:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://ashita.org/?p=307#comment-1125</guid>
		<description>Harini,

Good catch. I had fixed this bug in PirateQuesting several months back but obviously I&#039;d forgotten to update this blog entry. 

Needed to add:

&lt;code&gt;
	if (typeof Cc == &quot;undefined&quot;) {
		var Cc = Components.classes;
	}
	if (typeof Ci == &quot;undefined&quot;) {
		var Ci = Components.interfaces;
	}
&lt;/code&gt;

to the httpRequestObserver methods as they operate in a different scope than TracingListener. Firebug&#039;s const values were still valid though and the oversight was missed in testing.</description>
		<content:encoded><![CDATA[<p>Harini,</p>
<p>Good catch. I had fixed this bug in PirateQuesting several months back but obviously I&#8217;d forgotten to update this blog entry. </p>
<p>Needed to add:</p>
<p><code><br />
	if (typeof Cc == "undefined") {<br />
		var Cc = Components.classes;<br />
	}<br />
	if (typeof Ci == "undefined") {<br />
		var Ci = Components.interfaces;<br />
	}<br />
</code></p>
<p>to the httpRequestObserver methods as they operate in a different scope than TracingListener. Firebug&#8217;s const values were still valid though and the oversight was missed in testing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harini</title>
		<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/comment-page-1/#comment-1123</link>
		<dc:creator>Harini</dc:creator>
		<pubDate>Thu, 22 Apr 2010 12:54:00 +0000</pubDate>
		<guid isPermaLink="false">http://ashita.org/?p=307#comment-1123</guid>
		<description>Hi Jonathan,

Tnx for this article. I got my extension to listen in on XHR request using this code but I have a problem, the code only works if firebug is installed! Without firebug the onStart, onDataAvailable and onStopRequest all get value as &#039;undefined&#039; for their request parameter(i didn&#039;t check for other parameters). But whenever firebug is also installed in the browser the request value gets passed and everything works.

Can you pls let me how i can fix this?

tnx
Harini</description>
		<content:encoded><![CDATA[<p>Hi Jonathan,</p>
<p>Tnx for this article. I got my extension to listen in on XHR request using this code but I have a problem, the code only works if firebug is installed! Without firebug the onStart, onDataAvailable and onStopRequest all get value as &#8216;undefined&#8217; for their request parameter(i didn&#8217;t check for other parameters). But whenever firebug is also installed in the browser the request value gets passed and everything works.</p>
<p>Can you pls let me how i can fix this?</p>
<p>tnx<br />
Harini</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Fingland</title>
		<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/comment-page-1/#comment-834</link>
		<dc:creator>Jonathan Fingland</dc:creator>
		<pubDate>Mon, 01 Mar 2010 21:08:51 +0000</pubDate>
		<guid isPermaLink="false">http://ashita.org/?p=307#comment-834</guid>
		<description>@Maurico

piratequesting is an add-on I made for the browser game at &lt;a href=&quot;http://www.piratequest.net&quot; rel=&quot;nofollow&quot;&gt;www.piratequest.net&lt;/a&gt;. You can download the add-on at &lt;a href=&quot;http://pq.ashita.org&quot; rel=&quot;nofollow&quot;&gt;pq.ashita.org&lt;/a&gt; and test it out. Unfortunately I haven&#039;t updated it in a while and it is no longer compatible with the current version of Firefox. If you turn off version compatibility checking it works just fine.</description>
		<content:encoded><![CDATA[<p>@Maurico</p>
<p>piratequesting is an add-on I made for the browser game at <a href="http://www.piratequest.net" rel="nofollow">http://www.piratequest.net</a>. You can download the add-on at <a href="http://pq.ashita.org" rel="nofollow">pq.ashita.org</a> and test it out. Unfortunately I haven&#8217;t updated it in a while and it is no longer compatible with the current version of Firefox. If you turn off version compatibility checking it works just fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mauricio Gaueca F.</title>
		<link>http://www.ashita.org/howto-xhr-listening-by-a-firefox-addon/comment-page-1/#comment-833</link>
		<dc:creator>Mauricio Gaueca F.</dc:creator>
		<pubDate>Mon, 01 Mar 2010 20:49:30 +0000</pubDate>
		<guid isPermaLink="false">http://ashita.org/?p=307#comment-833</guid>
		<description>Thanks Jonathan, this is a great article.
What is piratequesting object? I&#039;m trying to run this example, but i get an error.

Best regards.</description>
		<content:encoded><![CDATA[<p>Thanks Jonathan, this is a great article.<br />
What is piratequesting object? I&#8217;m trying to run this example, but i get an error.</p>
<p>Best regards.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
