<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>code-diesel &#187; firefox</title>
	<atom:link href="http://www.codediesel.com/tag/firefox/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Peeking inside FireFox using MozRepl</title>
		<link>http://www.codediesel.com/tools/peeking-inside-firefox-using-mozrepl/</link>
		<comments>http://www.codediesel.com/tools/peeking-inside-firefox-using-mozrepl/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 13:06:43 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[firefox]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2655</guid>
		<description><![CDATA[I usually use Selenium for testing web applications or some quick screen scraping jobs. It is more than adequate for my purpose as most of the time I work on the back-end code. But if you spend most of your time working on Ajax, scraping and other JavaScript jobs, then you need more powerful tools [...]]]></description>
			<content:encoded><![CDATA[<p>I usually use Selenium for testing web applications or some quick screen scraping jobs. It is more than adequate for my purpose as most of the time I work on the back-end code. But if you spend most of your time working on Ajax, scraping and other JavaScript jobs, then you need more powerful tools at your disposal. The one I think you will find useful is MozRepl. With it you can connect to Firefox and other Mozilla apps, explore and modify them from the inside, execute Javascript, peek into HTML pages, examine functions and variables, all while FireFox is running.<br />
<span id="more-2655"></span><br />
<a target="_blank" href="https://github.com/bard/mozrepl/wiki#Emacs">MozRepl</a> &#8211; a read-eval-print loop for Firefox &#8211; is a Firefox extension that acts like a TCP/IP socket server within Firefox. You can then connect to the socket using any client application and send commands to Firefox. Each command you send to Firefox using MozRepl is executed as if it was run from the browser, which gives you the ability to do anything that you would normally do using Javascript.</p>
<h4>Installing MozRepl</h4>
<p>Before proceeding you need to first install MozRepl which comes as a Firefox extension.  Head over to <a target="_blank" href="https://github.com/bard/mozrepl/wiki/">github</a> to download and install. Once you have installed it, go to Firefox Tools menu and select MozLab → Start MozRepl. MozRepl will now be listening for connections on the default port 4242.</p>
<h4>Connecting to MozRepl</h4>
<p>Now that we have MozRepl up and running we can easily connect to it using Telnet. By default MozRepl listens on port 4242, which however you can change to your liking from the MozRepl menu.</p>

<div class="wp_codebox"><table><tr id="p265510"><td class="code" id="p2655code10"><pre class="text" style="font-family:monospace;">C:\&gt; telnet localhost 4242</pre></td></tr></table></div>

<p>You will get the following response if you are correctly connected to MozRepl.</p>

<div class="wp_codebox"><table><tr id="p265511"><td class="code" id="p2655code11"><pre class="text" style="font-family:monospace;">Welcome to MozRepl.
 - If you get stuck at the &quot;...&gt;&quot; prompt, enter a semicolon (;) 
at the beginning of the line to force evaluation.
 - If you get errors after every character you type, see http://github.c
om/bard/mozrepl/wikis/troubleshooting (short version: stop using 
Microsoft telnet, use netcat or putty instead)
Current working context: chrome://browser/content/browser.xul
Current input mode: syntax
&nbsp;
repl&gt;</pre></td></tr></table></div>

<p>If you have trouble connecting using Windows telnet or encounter some inconsistent behavior,  you can use <a href="http://www.putty.org/">Putty</a> instead. A typical putty connection setup is shown below, note the &#8216;telnet&#8217; radio selection:</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/05/putty.png"><img src="http://www.codediesel.com/wp-content/uploads/2010/05/putty.png" alt="" title="putty" width="453" height="440" class="aligncenter size-full wp-image-2657" /></a></p>
<p>Also make sure you check the &#8216;Implicit CR in every LF&#8217; check box.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/12/putty-config.gif"><img src="http://www.codediesel.com/wp-content/uploads/2010/12/putty-config.gif" alt="" title="putty-config" width="455" height="441" class="aligncenter size-full wp-image-2770" /></a></p>
<p>Once you are connected to the server you will be presented with the following prompt:</p>

<div class="wp_codebox"><table><tr id="p265512"><td class="code" id="p2655code12"><pre class="text" style="font-family:monospace;">repl&gt;</pre></td></tr></table></div>

<p>Lets try a standard greeting.</p>

<div class="wp_codebox"><table><tr id="p265513"><td class="code" id="p2655code13"><pre class="text" style="font-family:monospace;">repl&gt; window.alert(&quot;Hello World!&quot;)</pre></td></tr></table></div>

<p>MozRepl is now ready to accepts your commands. Lets try a simple one given below. The first line is the command we send to MozRepl to get the title of the current open Firefox window, while the second line is the response.</p>

<div class="wp_codebox"><table><tr id="p265514"><td class="code" id="p2655code14"><pre class="text" style="font-family:monospace;">repl&gt; document.title
&quot;Tutorial - mozrepl - GitHub - Mozilla Firefox&quot;</pre></td></tr></table></div>

<p>Lets try changing the document title of the current Firefox window:</p>

<div class="wp_codebox"><table><tr id="p265515"><td class="code" id="p2655code15"><pre class="text" style="font-family:monospace;">repl&gt; document.title = &quot;hello&quot;</pre></td></tr></table></div>

<p>Use the following to get all the function and variables in Firefox:</p>

<div class="wp_codebox"><table><tr id="p265516"><td class="code" id="p2655code16"><pre class="text" style="font-family:monospace;">repl&gt; repl.look()</pre></td></tr></table></div>

<p>This is just a sampler, you can do a whole lot of things using MozRepl, check this <a target="_blank" href="http://www.youtube.com/watch?v=5RSnHN6S52c">video</a> for some more examples.</p>
<h4>Connecting to MozRepl with PHP</h4>
<p>As MozRepl creates a server on port 4242, we can easily connect to it via PHP and send commands to it. A small example is given below which you will need to run from the command line. The following code sends 3 commands to the MozRepl server and prints the responses. It uses the <em>socketHelper</em> class to do the dirty work of socket processing.</p>

<div class="wp_codebox"><table><tr id="p265517"><td class="code" id="p2655code17"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'socketHelper.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Commands to send to  MozRepl */</span>
&nbsp;
<span style="color: #000088;">$commands</span><span style="color: #339933;">=</span><span style="color: #009933; font-style: italic;">&lt;&lt;&lt;EOD
repl.whereAmI()
content.location.href = 'http://google.com'
repl.quit()
EOD</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$firefox_socket</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SocketHelper<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$firefox_socket</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$commands</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #339933;">==</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span> <span style="color: #009933; font-style: italic;">//Skip blank lines</span>
    <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$firefox_socket</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send_command</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Code for <em>socketHelper</em> class</p>

<div class="wp_codebox"><table><tr id="p265518"><td class="code" id="p2655code18"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* socketHelper.php */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> SocketHelper
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$address</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;127.0.0.1&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$port</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;4242&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$socket</span>  <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">=</span><span style="color: #990000;">socket_create</span><span style="color: #009900;">&#40;</span>AF_INET<span style="color: #339933;">,</span>SOCK_STREAM<span style="color: #339933;">,</span>SOL_TCP<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">socket_strerror</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">socket_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">address</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">port</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">socket_strerror</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">socket_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/** Send a command to MozRepl */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> send_command<span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$command</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">socket_write</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #009933; font-style: italic;">/* 
        Read from the Socket until we get a &quot;repl&gt;&quot; prompt, 
        or loop forever.
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> read<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$chunk</span> <span style="color: #339933;">=</span> <span style="color: #990000;">socket_read</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">65536</span><span style="color: #339933;">,</span>PHP_BINARY_READ<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chunk</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Error reading from socket<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chunk</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #009933; font-style: italic;">//No more data</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|^(.*)\s*repl\d*&gt;\s*$|s'</span><span style="color: #339933;">,</span><span style="color: #000088;">$chunk</span><span style="color: #339933;">,</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$response</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$response</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$chunk</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>Security Warning</h4>
<p>Because MozRepl can directly poke inside FireFox it can practically work with anything &#8211; your bookmarks, cookies, cache etc, so security should be your prime concern. So do not ever allow outside connections in MozRepl (Tools menu → MozLab → Allow outside connections), unless you are sure what you are doing.</p>
<p>I&#8217;m still investigating the things I can do with MozRepl. If you have done some cool things of your own using it, please post your ideas here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/peeking-inside-firefox-using-mozrepl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Codediesel Firefox toolbar</title>
		<link>http://www.codediesel.com/tools/codediesel-firefox-toolbar/</link>
		<comments>http://www.codediesel.com/tools/codediesel-firefox-toolbar/#comments</comments>
		<pubDate>Tue, 19 May 2009 14:23:14 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[firefox]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=874</guid>
		<description><![CDATA[Firefox toolbar]]></description>
			<content:encoded><![CDATA[<p>A couple of days back I created a Firefox toolbar for my blog as an experiment in learning XUL. The toolbar is shown below. You can install the same from </a><a title="Install" href="/data/code/codediesel_toolbar.php">here</a>.</p>
<p><a href="/data/code/codediesel_toolbar.php"><img src="http://www.codediesel.com/wp-content/uploads/2009/05/toolbar.gif" alt="Install" title="Install" width="546" height="24" class="aligncenter size-full wp-image-940" /></a></p>
<p>Now you can create a toolbar for your own blog or site. The source for the toolbar can be downloaded from below after which you can edit the code to suit your site; to help you there is a nice reference for XUL elements <a target="_blank" href="https://developer.mozilla.org/en/XUL">here</a>. The idea for the post was inspired by <a target="_blank" href="http://davidwalsh.name/">david</a>.</p>
<div  class="download2">
<a href="http://www.codediesel.com/downloads/codedieselToolbar">Download Source</a><br />
<span>Downloads : 552  / File size : 23.2 kB</span>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/codediesel-firefox-toolbar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

