<?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>Software is hard</title>
	<atom:link href="http://www.softwareishard.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.softwareishard.com/blog</link>
	<description>More musings on software development</description>
	<lastBuildDate>Fri, 09 Aug 2024 12:19:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.7.33</generator>
	<item>
		<title>Modern React Component Testing with create-react-app, Jest, and Enzyme</title>
		<link>http://www.softwareishard.com/blog/testing/modern-react-component-testing-with-create-react-app-jest-and-enzyme/</link>
		<pubDate>Wed, 28 Jun 2017 14:11:19 +0000</pubDate>
		<dc:creator><![CDATA[Honza]]></dc:creator>
				<category><![CDATA[React]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.softwareishard.com/blog/?p=1181</guid>
		<description><![CDATA[This post is written by Charlie Crawford who teaches for appendTo, who offers React Training Courses for developer teams. There are many things to love about React, but one of the biggest pain points in React is project bootstrapping. As React takes a modular "roll your own" framework approach, it can take some time to [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><em>This post is written by Charlie Crawford who teaches for appendTo, who offers <a href="https://appendto.com/courses/react-training-courses/">React Training Courses</a> for developer teams.</em></p>
<p>There are many things to love about React, but one of the biggest pain points in React is project bootstrapping. As React takes a modular "roll your own" framework approach, it can take some time to get your project boilerplate up and running. Thankfully, <a href="https://github.com/facebookincubator/create-react-app">create-react-app</a> has come to the scene with powerful configuration free React boilerplate. While create-react-app tries to remain fairly agnostic and unopinionated, over time more and more functionality has been introduced into the project. Specifically, testing has progressed with the new revamped version of <a href="https://facebook.github.io/jest/">Jest</a> (The "official" Facebook React testing tool) That being said, <a href="https://github.com/airbnb/enzyme">Enzyme</a> (A popular third party React testing library by AirBnB) is still a vital part of the React testing stack. It can be a little unclear how create-react-app, Jest, and Enzyme should work Together. The <a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#writing-tests">official guide</a> offers some insights on how to load Enzyme into your project, but doesn’t really explain the role Enzyme plays. Let’s change that. </p>
<p><span id="more-1181"></span></p>
<h3>What Enzyme brings to the the table</h3>
<p>Enzyme brings all sorts of utility functions for testing React applications. However, the biggest benefit of using Enzyme is "<a href="http://airbnb.io/enzyme/docs/api/shallow.html">shallow-rendering</a>". Shallow rendering allows you to render a component, without rendering its children. This allows proper unit testing of React components. Let's say you are writing unit tests for a function a which invokes function b. If they are true unit tests - and not integration, end-to-end, or some other form of testing - the implementation of function b should not affect the unit tests of function a. Analogously, if you have React component A which renders sub-components B and C, you don't want the implementation of B and C affecting the unit tests for component A. Shallow rending is what makes this possible. Let’s see it in action with the beginnings of a typical Todo List app. </p>
<h3>The app we will be building</h3>
<p>We will be using vanilla React for this application. While this could easily be extended to Redux or other state management solutions, we will keep this tutorial focused on component testing. The app will consist of an App, TodoList, and Todo component. We will be bootstrapping this app with create-react-app, and will be using Enzyme and shallow rendering to facilitate writing true unit tests for the todoList component.</p>
<p>To begin, globally install create-react-app using yarn or npm. After installing, use the create-react-app to bootstrap the new application.</p>
<div class="dean_ch" style="white-space: wrap;">npm <span class="kw2">install</span> -g create-react-app<br />
create-react-app todo-testing</div>
<p>&nbsp;</p>
<p>cd into the todo-testing app directory and install enzyme</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">cd</span> todo-testing<br />
npm <span class="kw2">install</span> --save enzyme react-addons-test-utils</div>
<p>&nbsp;</p>
<p>cd into the src directory, and create the few files</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw3">cd</span> src<br />
<span class="kw2">touch</span> Todo.js TodoList.js Todo.<span class="kw3">test</span>.js TodoList.<span class="kw3">test</span>.js</div>
<p>&nbsp;</p>
<p>Go into App.js component, and tell it to render our future TodoList component.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">import</span> React, <span class="br0">&#123;</span> Component <span class="br0">&#125;</span> from <span class="st0">'react'</span>;<br />
<span class="kw2">import</span> <span class="st0">'./App.css'</span>;<br />
<span class="kw2">import</span> TodoList from <span class="st0">'./TodoList'</span>;<br />
&nbsp;<br />
<span class="kw2">class</span> App <span class="kw2">extends</span> Component <span class="br0">&#123;</span><br />
&nbsp; render<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &lt;div className=<span class="st0">&quot;App&quot;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;TodoList/&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; <span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;<br />
<span class="kw2">export</span> <span class="kw2">default</span> App;</div>
<p>&nbsp;</p>
<p>Next, let's write the TodoList Component.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">import</span> React, <span class="br0">&#123;</span> Component <span class="br0">&#125;</span> from <span class="st0">'react'</span>;<br />
<span class="kw2">import</span> Todo from <span class="st0">'./Todo'</span><br />
&nbsp;<br />
<span class="kw2">class</span> TodoList <span class="kw2">extends</span> Component <span class="br0">&#123;</span><br />
&nbsp; constructor<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">todos</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
&nbsp;<br />
&nbsp; addTodo<span class="br0">&#40;</span>todo<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">setState</span><span class="br0">&#40;</span><span class="br0">&#123;</span>todos: <span class="kw1">this</span>.<span class="me1">todos</span>.<span class="me1">concat</span><span class="br0">&#40;</span>todo<span class="br0">&#41;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
&nbsp;<br />
&nbsp; render<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &lt;div className=<span class="st0">&quot;App&quot;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;p&gt;Our Todo List&lt;/p&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="kw1">this</span>.<span class="me1">todos</span>.<span class="me1">map</span><span class="br0">&#40;</span>todo =&gt; &lt;Todo todo=<span class="br0">&#123;</span>todo<span class="br0">&#125;</span>/&gt;<span class="br0">&#41;</span><span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; <span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;<br />
<span class="kw2">export</span> <span class="kw2">default</span> TodoList;</div>
<p>&nbsp;</p>
<p>Before writing test cases for TodoList, let's stub out a Todo component<br />
so our code will compile.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">import</span> React, <span class="br0">&#123;</span> Component <span class="br0">&#125;</span> from <span class="st0">'react'</span>;<br />
&nbsp;<br />
<span class="kw2">const</span> Todo = <span class="br0">&#40;</span><span class="br0">&#41;</span> =&gt; <span class="br0">&#40;</span><br />
&nbsp; &lt;div&gt;&lt;/div&gt;<br />
<span class="br0">&#41;</span>;<br />
&nbsp;<br />
<span class="kw2">export</span> <span class="kw2">default</span> Todo;</div>
<p>&nbsp;</p>
<p>We can now write a testcase in TodoList.test.js</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">import</span> React from <span class="st0">'react'</span>;<br />
<span class="kw2">import</span> <span class="br0">&#123;</span> shallow <span class="br0">&#125;</span> from <span class="st0">'enzyme'</span>;<br />
<span class="kw2">import</span> TodoList from <span class="st0">'./TodoList'</span>;<br />
&nbsp;<br />
it<span class="br0">&#40;</span><span class="st0">'renders &quot;Our Todo List&quot;'</span>, <span class="br0">&#40;</span><span class="br0">&#41;</span> =&gt; <span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">const</span> wrapper = shallow<span class="br0">&#40;</span>&lt;TodoList/&gt;<span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw2">const</span> textHeader = &lt;p&gt;Our Todo List&lt;/p&gt;;<br />
&nbsp; expect<span class="br0">&#40;</span>wrapper.<span class="me1">contains</span><span class="br0">&#40;</span>textHeader<span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">toEqual</span><span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<p>&nbsp;</p>
<div class="dean_ch" style="white-space: wrap;">npm <span class="kw3">test</span><br />
Formatted <span class="kw3">test</span> output</div>
<p>&nbsp;</p>
<p>In addition to tests that use shallow rendering running much faster, the implementation of subcomponents largely won't affect the result of the unit test for this component. For example, let's change the implementation of the Todo component, and rerun the test </p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">import</span> React, <span class="br0">&#123;</span> Component <span class="br0">&#125;</span> from <span class="st0">'react'</span>;<br />
&nbsp;<br />
<span class="kw2">const</span> Todo = <span class="st0">''</span>;<br />
&nbsp;<br />
<span class="kw2">export</span> <span class="kw2">default</span> Todo;</div>
<p>&nbsp;</p>
<div class="dean_ch" style="white-space: wrap;">npm <span class="kw3">test</span><br />
Formatted <span class="kw3">test</span> output</div>
<p>&nbsp;</p>
<p>Despite Todo not even being a real React component, our unit test for TodoList still runs and passes! Now you can achieve truly isolated unit testing of your components, and improve the reliability of your React applications. </p>
<p>&nbsp;</p>
<p class="bullet">
]]></content:encoded>
			</item>
		<item>
		<title>Why Load Test?</title>
		<link>http://www.softwareishard.com/blog/testing/why-load-test/</link>
		<pubDate>Tue, 21 Feb 2017 11:53:08 +0000</pubDate>
		<dc:creator><![CDATA[Honza]]></dc:creator>
				<category><![CDATA[Page Load Performance]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.softwareishard.com/blog/?p=1159</guid>
		<description><![CDATA[Tips on why you want to load test your website, web apps and API’s in 2017. Plus - a few tips on setup and implementation. This post is written by Jaymi Tripp from Dotcom-Monitor. 1. You are expecting an influx in traffic or sales If you know that you will see an increase in visitors [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><em>Tips on why you want to load test your website, web apps and API’s in 2017. Plus - a few tips on setup and implementation.</em></p>
<p><em>This post is written by Jaymi Tripp from <a href="https://www.dotcom-monitor.com/">Dotcom-Monitor</a>.</em></p>
<h3>1. You are expecting an influx in traffic or sales</h3>
<p>If you know that you will see an increase in visitors to your website, load testing is crucial, and no website is invincible. In 2003 we saw with Amazon in a situation that ended in legal issues and server overload when someone entered incorrect data for the price of some popular electronic items at the time. Even the government is susceptible to crashes. We all remember this after the launch of Obama Care with the incredible page load times and constant glitches. Rumor has it that the site never went through any load testing scenarios and there was no information on what its capacity actually was. </p>
<p><span id="more-1159"></span></p>
<h3>2. Insight</h3>
<p>Knowing what you need to ensure your site performs under pressure is extremely valuable. This allows you to have the tools in place to ensure your website can weather the storm. The element of surprise is never appreciated in website performance. Insight into the functions and performance of your website will ensure happy customers and a website that functions as expected.</p>
<h3>3. You want to know what your user experience is like</h3>
<p>When using cloud based load testing software you can be given the ability to not only test, but to also record video of the test in progress. For example,  on <a href="https://loadview-testing.com/">LoadView-Testing.com</a>, a cloud based load testing platform– you can record the experience as your users see it and test right down to the very element on the page. LoadView uses<a href="https://www.everystep-automation.com/"> the EveryStep Automation Tool</a>  to do this. Best thing about the EveryStep Script Recorder? It’s free and also extremely easy to use. Below is a screen shot of the interface while recording a script. </p>
<p><a href="http://www.softwareishard.com/blog/wp-content/load-test.png" rel="lightbox[1159]"><img src="http://www.softwareishard.com/blog/wp-content/load-test-300x182.png" alt="" title="" width="300" height="182" class="aligncenter size-medium wp-image-1167" align="center" srcset="http://www.softwareishard.com/blog/wp-content/load-test-300x182.png 300w, http://www.softwareishard.com/blog/wp-content/load-test.png 1000w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<h3>4. You want to identify third party issues when under heavy load</h3>
<p>Perhaps you are using a CDN to host all of your images, or you have a chat function through a third party vendor. It is important that your visitors are able to use and see the features of your website regardless how many users are accessing it. Load testing will allow you to know just which applications are failing to perform and in turn, hold up their end of your service agreement.</p>
<h3>5. You have an e-commerce website</h3>
<p>If your website is your bread and butter, then you better make sure it functions. This is especially important for websites with a shopping cart. Orders not delivered or sent to wrong address, customers charged for items they never bought, all of these could be side effects of heavy traffic. Your conversion funnel should be set up for load and stress testing on a regular so you know how it is functioning during peak times. This gives you great insight into why your customers could be abandoning your site.</p>
<h3>6. You did some major (or minor) updates</h3>
<p>Just like I mentioned above with the Amazon pricing mishap, this can also take other forms, such as a recent redesign or platform update. Establishing baseline performance markers and seeing what your pages look like upon load, in real browsers to real users will lower the risk of failure. After installing an update, those performance markers can help narrow the possibility that your updates caused the performance of your website to actually falter. </p>
<p></p>
<h2>Tips when setting up load testing</p>
<h2>
<p></p>
<h3>1. Use an outside source</h3>
<p>This will allow you to test from multiple locations around the world and simulate actual traffic more accurately, as well as keep your in-house costs down. <a href="https://loadimpact.com/">Load Impact</a>, as well as <a href="https://www.loadview-testing.com/">LoadView</a>, <a href="https://loader.io/">Loader.io</a> and <a href="https://www.blazemeter.com/">BlazeMeter</a> all allow for you to set up testing locations around the world and many of them at the same time.</p>
<h3>2. Ensure your service of choice provides you with actionable data</h3>
<p>What good is load testing if you don’t have enough information to take action after testing completes? While all services will give you reports, very few offer customizable reporting. LoadView <a href="https://www.dotcom-monitor.com/web-performance-reports/web-performance-dashboards/">offers a nice drag and drop reporting dashboard</a> (<a href="https://youtu.be/NRtvsrzLY9o">seen here</a>) for adding graphs and reports, Load Impact will go as far as letting you create custom graphs. Both let you export your data for every single request made, which sets these two platforms apart from the others who offer no customization at all.</p>
<h3>3. Choose a provider with the support you need</h3>
<p>If you need a higher level of support, be sure to choose a company that offers it. Using LoadView, I learned they have a full support staff, <a href="https://wiki.dotcom-monitor.com/knowledge-base/">a helpful knowledge base</a> and a series of <a href="https://wiki.dotcom-monitor.com/video-tutorials/">video tutorials</a> that are a big help. </p>
<h3>4. Know what services your platform utilizes</h3>
<p>For instance, <a href="https://www.blazemeter.com/usecases#features-performance">Blazemeter</a> uses Amazon Web Services and Google Cloud Platform Live, while LoadView uses both of those services, they also utilize Rackspace MyCloud. From what I can see, it is one of the few that utilizes three platforms instead of the standard two.</p>
<h3>5. Define baseline performance metrics</h3>
<p>This is critical in any area of online testing. Baseline metrics will establish where you are now, when a load test starts to impact the performance of your website or apps and then finally when it goes into failure. Another thing you might want to consider, what would constitute as failure for your website or applications? Establish these metrics right away so you know what you are looking for in terms of performance. Using LoadView, I have been able to store historical data since opening my account, which has been extremely helpful when reporting.</p>
<p></p>
<h2>Conclusion</h2>
<p></p>
<p>In 2017 you are hard pressed to find a reason NOT to perform regular performance checks on your websites, web apps or other online devices. Most of the services mentioned above also come with an <a href="https://www.dotcom-tools.com/">entire suite of monitoring solutions</a>. LoadView is a part of the <a href="https://www.dotcom-tools.com/">Dotcom-Monitor load testing platform</a>, therefore every account has access to web page speed tests, mail server testing, streaming video test tools, ping testing and much more within their dashboard. Testing frequently and thoroughly is the only way to ensure your website and web apps are up and running even when you are not looking. Customize your alerts to send you text messages, emails or other forms of notifications so you and those responsible can respond quickly to problems before it affects your customers or bottom line.</p>
<p></p>
<p>Jaymi Tripp</p>
]]></content:encoded>
			</item>
		<item>
		<title>Inspecting WebSocket Traffic with Firefox Developer Tools</title>
		<link>http://www.softwareishard.com/blog/planet-mozilla/inspecting-websocket-traffic-with-firefox-developer-tools/</link>
		<pubDate>Mon, 11 Apr 2016 13:01:07 +0000</pubDate>
		<dc:creator><![CDATA[Honza]]></dc:creator>
				<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Planet Mozilla]]></category>
		<category><![CDATA[WebSockets]]></category>

		<guid isPermaLink="false">http://www.softwareishard.com/blog/?p=1102</guid>
		<description><![CDATA[WebSocket monitor is an extension to Firefox developer tools that can be used to monitor WebSocket connections in Firefox. It allows inspecting all data sent and received. It's been a while since we published first version of our add-on for inspecting WebSocket traffic and it's good time to summarize all new features and show how [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><em>WebSocket monitor is an extension to Firefox developer tools that can be used to monitor WebSocket connections in Firefox. It allows inspecting all data sent and received.</em></p>
<p>It's been a while since we published first version of our add-on for inspecting WebSocket traffic and it's good time to summarize all new features and show how it's integrated with Firefox Developer tools.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/websocket-monitor/">Download</a> signed version of this add-on from AMO. The source code with further documentation is available on <a href="https://github.com/firebug/websocket-monitor">github</a>.</p>
<p><i style="color:red"> Update 2019/10/21: New <a href="https://hacks.mozilla.org/2019/10/firefoxs-new-websocket-inspector/">WebSocket inspector</a> has been released in Firefox 71</i></p>
<p>WebSocket Monitor can be used to track any WS connection, but following protocols have an extra support: <strong>Socket.IO, SockJS, Plain JSON, WAMP, MQTT</strong>.</p>
<p></p>
<p><a href="http://www.softwareishard.com/blog/wp-content/mainbig.png" rel="lightbox[1102]"><img src="http://www.softwareishard.com/blog/wp-content/main.png" alt="" title="" width="520" height="210" class="aligncenter size-full wp-image-1135" srcset="http://www.softwareishard.com/blog/wp-content/main.png 520w, http://www.softwareishard.com/blog/wp-content/main-300x121.png 300w" sizes="(max-width: 520px) 100vw, 520px" /></a><br />
(click to enlarge)</p>
<p><span id="more-1102"></span></p>
<h3>Introduction</h3>
<p>After the add-on is installed, open Firefox Developer Tools (F12 on Win or ⌥⌘I on OSX) and switch into a new <strong>Web Sockets</strong> panel. The panel displays list of frames sent/received by all WebSockets connections on the current page as well as <em>Connect</em> and <em>Disconnect</em> events.</p>
<p><img src="http://www.softwareishard.com/blog/wp-content/frames.png" alt="" title="" width="520" height="239" class="aligncenter size-full wp-image-1114" align="center" srcset="http://www.softwareishard.com/blog/wp-content/frames.png 520w, http://www.softwareishard.com/blog/wp-content/frames-300x137.png 300w" sizes="(max-width: 520px) 100vw, 520px" /></p>
<p>The screenshot above shows one <em>Connect</em> event, one <em>Sent</em> frame and one <em>Received</em> frame. There is also a summary at the bottom of the list showing number of frames in the list, total size of transferred payload and total time since the first frame.</p>
<p>The screenshot below shows content of the side panel that displays all details of the selected packet.</p>
<p style="text-align:center"><img src="http://www.softwareishard.com/blog/wp-content/side-panel2.png" alt="" title="side-panel" width="319" height="384" class="aligncenter size-full wp-image-1122" srcset="http://www.softwareishard.com/blog/wp-content/side-panel2.png 319w, http://www.softwareishard.com/blog/wp-content/side-panel2-249x300.png 249w" sizes="(max-width: 319px) 100vw, 319px" /></p>
<h3>Filtering</h3>
<p>The extension allows simple filtering of the frame list. It's possible to filter using a keyword where only frames with the keyword in the payload are displayed. Or you might pick a connection ID and see only frames sent/received through that connection.</p>
<p><img src="http://www.softwareishard.com/blog/wp-content/filter2.png" alt="" title="filter2" width="520" height="253" class="aligncenter size-full wp-image-1125" srcset="http://www.softwareishard.com/blog/wp-content/filter2.png 520w, http://www.softwareishard.com/blog/wp-content/filter2-300x145.png 300w" sizes="(max-width: 520px) 100vw, 520px" /></p>
<h3>Protocols</h3>
<p>WebSocket Monitor allows inspecting any WS connection, but there is an extra support for the following protocols:</p>
<ul>
<li><a href="http://socket.io/">Socket.IO</a></li>
<li><a href="https://github.com/sockjs">SockJS</a></li>
<li>Plain JSON</li>
<li><a href="http://wamp-proto.org/">WAMP</a></li>
<li><a href="http://mqtt.org/">MQTT</a></li>
</ul>
<p>These protocols introduce an extra side bar with parsed payload. See the next screenshot that shows parsed SocketIO frame payload as an expandable tree allowing quick inspection.</p>
<p><img src="http://www.softwareishard.com/blog/wp-content/socket.io_.png" alt="" title="socket.io" width="520" height="220" class="aligncenter size-full wp-image-1127" srcset="http://www.softwareishard.com/blog/wp-content/socket.io_.png 520w, http://www.softwareishard.com/blog/wp-content/socket.io_-300x126.png 300w" sizes="(max-width: 520px) 100vw, 520px" /></p>
<h3>Table and Chat Perspectives</h3>
<p>There are two ways how to visualize frames. Apart from the <strong>Tabular View</strong> (see the screenshot above) there is also a <strong>Chat View</strong> that uses well know 'user-chat' approach (used in various messengers).</p>
<p><img src="http://www.softwareishard.com/blog/wp-content/perspective.png" alt="" title="" width="520" height="224" class="aligncenter size-full wp-image-1129" srcset="http://www.softwareishard.com/blog/wp-content/perspective.png 520w, http://www.softwareishard.com/blog/wp-content/perspective-300x129.png 300w" sizes="(max-width: 520px) 100vw, 520px" /></p>
<h3>Inline Data Preview</h3>
<p>Both perspectives offers also an inline data preview. You don't have to always select the frame and go to the side bar, just open the data directly in the frame.</p>
<p><img src="http://www.softwareishard.com/blog/wp-content/inline.png" alt="" title="" width="520" height="252" class="aligncenter size-full wp-image-1131" srcset="http://www.softwareishard.com/blog/wp-content/inline.png 520w, http://www.softwareishard.com/blog/wp-content/inline-300x145.png 300w" sizes="(max-width: 520px) 100vw, 520px" /></p>
<p></p>
<p>There are more small and nifty features so, don't forget to checkout our <a href="https://github.com/firebug/websocket-monitor/wiki">wiki</a> if you are interested!</p>
<h3>Resources</h3>
<ul>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/websocket-monitor/">Download</a></li>
<li><a href="https://github.com/firebug/websocket-monitor">Source Code</a></li>
<li><a href="https://github.com/firebug/websocket-monitor/wiki">Wiki</a></li>
<li><a href="http://janodvarko.cz/test/websockets/">Test page</a></li>
</ul>
]]></content:encoded>
			</item>
		<item>
		<title>Pixel Perfect 2, Developer Tool Extension Architecture</title>
		<link>http://www.softwareishard.com/blog/extension-architecture/pixel-perfect-2-developer-tool-extension-architecture/</link>
		<comments>http://www.softwareishard.com/blog/extension-architecture/pixel-perfect-2-developer-tool-extension-architecture/#comments</comments>
		<pubDate>Tue, 31 Mar 2015 16:01:06 +0000</pubDate>
		<dc:creator><![CDATA[Honza]]></dc:creator>
				<category><![CDATA[Extension Architecture]]></category>
		<category><![CDATA[Pixel Perfect]]></category>

		<guid isPermaLink="false">http://www.softwareishard.com/blog/?p=995</guid>
		<description><![CDATA[I have been recently working on Pixel Perfect extension that allows web designers to overlay a page with semi transparent image and tweak the page HTML/CSS with per pixel precision - till it's matching the overlay. This extension hasn't been working for several years (not maintained) and since requested by many users Firebug Working Group [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I have been recently working on <a href="https://github.com/firebug/pixel-perfect/wiki">Pixel Perfect</a> extension that allows web designers to overlay a page with semi transparent image and tweak the page HTML/CSS with per pixel precision - till it's matching the overlay.</p>
<p>This extension hasn't been working for several years (not maintained) and since requested by many users <a href="https://getfirebug.com/wiki/index.php/Firebug_Working_Group">Firebug Working Group</a> (FWG) got the opportunity to build that again and on top of native Developer tools in Firefox.</p>
<p>We had two goals in mind when building the extension:</p>
<ul>
<li>Make the Pixel Perfect feature available again</li>
<li>Show how to build a real world extension on top of native API and tools in Firefox</li>
</ul>
<p>This post focuses on the internal architecture. There is <a href="https://hacks.mozilla.org/2015/03/pixel-perfect-2-extension-for-firefox-developer-tools/">another post</a> if you rather interested in the feature itself.</p>
<p><img alt="" src="http://softwareishard.com/extensions/pixelperfect/images/logo_64x64.png" class="aligncenter" align="center" width="64" height="64" /></p>
<p><span id="more-995"></span></p>
<h3>Requirements</h3>
<p>The extension is based on Add-on SDK as well as native platform API and we are also using <a href="https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Getting_Started_%28jpm%29">JPM</a> command line tool for building the final XPI.</p>
<p>There are several design decisions we made:</p>
<ul>
<li>Support upcoming multiprocess browser (<a href="https://wiki.mozilla.org/Electrolysis">e10s</a>)</li>
<li>Support remote devices (connected over <a href="https://wiki.mozilla.org/Remote_Debugging_Protocol">RDP</a>)</li>
<li>Use known web technologies to build the UI (<a href="http://facebook.github.io/react/">ReactJS</a>)</li>
</ul>
<p>These decisions had obviously an impact on the internal architecture described below.</p>
<h3>Multiprocess Browser (e10s)</h3>
<p>There are <a href="https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox">already</a> <a href="https://billmccloskey.wordpress.com/2013/12/05/multiprocess-firefox/">articles</a> about upcoming multiprocess support in Firefox, so just briefly what this means for extensions => specifically for Pixel Perfect. The basic stone in this concept is that web page is running in different process than the rest of the browser (where rest of the browser includes also extensions).</p>
<p><img alt="" src="http://www.softwareishard.com/images/posts/pixelperfect-architecture/multiprocess.png" class="aligncenter" width="520" height="190" align="center"/></p>
<ul>
<li><strong>Pixel Perfect 2 UI</strong> (the rest of the browser) is on the left side. It can't access the page content directly since it runs in different process (or it can even run on remote device, but more about that later).</li>
<li><strong>Web Page</strong> is on the right side, it runs in its own content process. It's secure (one of the main points of e10s) since it isn't that simple to access it (not even for extension developers <img src="https://s.w.org/images/core/emoji/2.2.1/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></li>
</ul>
<p>Pixel Perfect 2 (PP2), needs to properly cross the process boundary, setup messaging and deliver an image layer into the page content. The communication between processes is done using <a href="https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/The_message_manager">message managers</a> that usually exchange JSON based packets with data.</p>
<h3>Remote Debugging Protocol</h3>
<p>Another challenge is making new features remotable. Don't worry, there is already API in place that allows implementing astounding things.</p>
<p>The user scenario for PP2 is as follows:</p>
<ul>
<li>The user runs Developer Toolbox and PP2 on his desktop machine.</li>
<li>The Toolbox connects to an instance of Firefox running on a remote device.</li>
<li>The user picks a new layer (an image file) on his desktop.</li>
<li>The layer (image) appears inside loaded web page on the remote device.</li>
</ul>
<p>Awesome, right? The user can tweak even a mobile device screens to pixel perfection!</p>
<p>PP2 needs to figure out yet a bit more to be remotable. There is not only a process boundary, but also a network boundary to cross. Let's see new and more detailed picture.</p>
<p><img alt="" src="http://www.softwareishard.com/images/posts/pixelperfect-architecture/remote.png" class="aligncenter" width="520" height="355" /></p>
<ul>
<li><strong>Pixel Perfect 2 UI</strong> runs on the client side (in the chrome process). This is the desktop machine in our use case. It communicates with a <em>Front</em> object (RDP terminology).</li>
<li><strong>Front</strong> represents a proxy to the content process (local or remote). Executing methods on this object causes sending RDP packet cross processes and the network to the back-end (locale or remote device). All through RDP connection.</li>
<li><strong>Actor</strong> is an object that receives packets from the <em>Front</em> object. The <em>Actor</em> already lives in a content process (in case of PP2), and so it has direct access to the web page. This object is responsible for rendering layers (images) within the page. Actor also sends messages back (e.g. when layers are dragged inside the page, to update coordinates on the client).</li>
<li><strong>In-page Layer</strong> This is the image rendered over the page content. Note that images are not inserted directly into the page content DOM (that could be dangerous). They are rather rendered within a canvas that overlays the entire page. There are platform API for this and element highlighter (used by the Inspector panel) is also using this approach.</li>
</ul>
<p>One thing to note, the RDP connection between <em>Front</em> and <em>Actor</em> crosses the network boundary as well as gets into a content process on the back-end automatically. It's also possible to create an <em>Actor</em> that lives in the chrome process on the back-end. But more about that in another post (let me know if you are interested).</p>
<h3>User Interface</h3>
<p>Pixel Perfect 2 UI consists from one floating popup window that allows layer registration. The window looks like as follows.</p>
<p><img alt="" src="http://www.softwareishard.com/images/posts/pixelperfect-architecture/popup.png" class="aligncenter" width="473" height="296" align="center"/></p>
<p>Btw. the popup can be opened by clicking on a button available in the main Firefox toolbar (and there is also a context menu with links to some online resources).</p>
<p><img alt="" src="http://www.softwareishard.com/images/posts/pixelperfect-architecture/start-button.png" class="aligncenter" width="361" height="252" align="center"/></p>
<p>Implementing user interface is often hard and one of our goals was also showing how to use well known web technologies when building add-on. The popup window consists from one <code>&lt;iframe&gt;</code> element that loads standard HTML page bundled within the add-on package (xpi). The page is using <a href="http://requirejs.org/">RequireJS</a> + <a href="http://facebook.github.io/react/">ReactJS</a> web stack to build the UI. Of course you can use any library you like to generate the markup.</p>
<p>There is yet another great thing. The frame is using content privileges only (<code>type="content"</code> and <code>resource://</code> protocol for the content URL), not chrome privileges at all. It's safe just like any page loaded from the wild internet.</p>
<h3>Architecture</h3>
<p>Let's sum everything up and see the final picture linked with the actual <a href="https://github.com/firebug/pixel-perfect/">source code</a>.</p>
<p><img alt="" src="http://www.softwareishard.com/images/posts/pixelperfect-architecture/architecture.png" class="aligncenter" width="512" height="406" /></p>
<p>The explanation goes from top to bottom (client side -> back-end) starting with the PP2 UI.</p>
<ul>
<li><a href="https://github.com/firebug/pixel-perfect/blob/master/data/popup.html">popup.html</a> This is the Popup window. It consists from bunch of ReactJS templates (see the files in the same directory). The communication with <code>PixelPerfectPopup</code> object (<em>pixel-perfect-popup.js</em>) that lives in chrome content is done through message manager and JSON packets. Everything what lives in the <a href="https://github.com/firebug/pixel-perfect/tree/master/data">data</a> directory has content privileges. Stuff in <a href="https://github.com/firebug/pixel-perfect/tree/master/lib">lib</a> directory has chrome privileges.</li>
<li><a href="https://github.com/firebug/pixel-perfect/blob/master/lib/pixel-perfect-popup.js">pixel-perfect-popup.js</a> <code>PixelPerfectPopup</code> object is implemented in this module. It's responsible for communication with the popup window as well as communication with the back-end through <code>PixelPerfectFront</code> (<em>pixel-perfect-front.js</em>). If the user appends a new layer <code>panel.html</code> sends a new event to <code>PixelPerfectPopup</code>. It stores the layer in local store (a json file) and sends packet including an image data to the back-end <code>PixelPerfectActor</code>. The Actor gets access to the Canvas and renders the image.</li>
<li><a href="https://github.com/firebug/pixel-perfect/blob/master/lib/pixel-perfect-store.js">pixel-perfect-store.js</a> <code>PixelPerfectStore</code> is implemented in this file. It's responsible for layer persistence. All is stored inside a JSON file within the current browser profile directory.</li>
<li><a href="https://github.com/firebug/pixel-perfect/blob/master/lib/pixel-perfect-front.js">pixel-perfect-front.js</a> <code>PixelPerfectFront</code> is implemented in this file. It represents the proxy to the backend. The code is nice and simple, most of the stuff is handled by the RDP protocol automatically.</li>
<li><a href="https://github.com/firebug/pixel-perfect/blob/master/lib/pixel-perfect-actor.js">pixel-perfect-actor.js</a> <code>PixelPerfectActor</code> is implemented in this file. This file (a module) is loaded and evaluated on the backend. So, carefully with module dependencies, the backend can be a mobile device. All necessary stuff need to be sent from the client (e.g. a stylesheet). The actor uses Anonymous Content API and renders the layer/image received from the client. It also sends events back to the client. E.g. if a layer is dragged within the page, it sends new coordinates to the <code>PixelPerfectFront</code>, then it's forwarded to <code>PixelPerfectPopup</code> and further to <code>popup.html</code>to update the final ReactJS template.<br />
If you are ReactJS fan, you'll love the code. The JSON packet received all the way from the back-end actor (crossing process, network and security boundaries) is finally passed to <code>panel.setState(packet)</code> method to automatically update the UI. Oh, yeah, pure pleasure for passionate developer <img src="https://s.w.org/images/core/emoji/2.2.1/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></li>
</ul>
<p>That's it for now. The rest is in the <a href="https://github.com/firebug/pixel-perfect">source code</a> (there are a lot of comments, <a href="https://github.com/firebug/pixel-perfect/issues">ping</a> me if you need some more). </p>
<div class="bullet">&nbsp;</div>
<p></p>
<p>We (Firebug Working Group) care a lot about extensibility of native developer tools in Firefox and as we are making progress on new generation of Firebug we are also building new extensible API on the platform. If you want to know more about how to build developer (or designer) tool extensions, stay tuned. The next post will start a fresh new tutorial: <strong>Extending Firefox Developer Tools</strong></p>
<h3>Resources</h3>
<ul>
<li><a href="https://github.com/firebug/pixel-perfect/">Source Repository</a></li>
<li><a href="https://groups.google.com/forum/#!forum/firebug">Newsgroups</a> (yes, use the Firebug newsgroup)</li>
<li><a href="https://github.com/firebug/pixel-perfect/issues">Issue Tracker</a></li>
</ul>
<p></p>
<p>Jan 'Honza' Odvarko</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.softwareishard.com/blog/extension-architecture/pixel-perfect-2-developer-tool-extension-architecture/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Firebug Internals II. &#8211; Unified object rendering</title>
		<link>http://www.softwareishard.com/blog/firebug/firebug-internals-ii-unified-object-rendering/</link>
		<pubDate>Tue, 10 Jun 2014 15:20:54 +0000</pubDate>
		<dc:creator><![CDATA[Honza]]></dc:creator>
				<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Firebug]]></category>
		<category><![CDATA[Planet Mozilla]]></category>

		<guid isPermaLink="false">http://www.softwareishard.com/blog/?p=964</guid>
		<description><![CDATA[Firebug 2 (released today!) uses number of internal architectural concepts that help to implement new features as well as effectively maintain the code base. Using transparent architecture and well known design patterns has always been one of the key strategies of the (relatively small) Firebug team that allows us maintain rather large set of features [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><strong>Firebug 2</strong> (<a href="http://blog.getfirebug.com/2014/06/10/firebug-2-0/">released today</a>!) uses number of internal architectural concepts that help to implement new features as well as effectively maintain the code base.</p>
<p>Using transparent architecture and well known design patterns has always been one of the key strategies of the (relatively small) Firebug team that allows us maintain rather large set of features in Firebug.</p>
<p>This post describes the way how Firebug deals with JavaScript object representation and the concept ensuring that an object is always rendered the same way across entire Firebug UI.</p>
<ul>
<li><strong>Firebug 2.0</strong> is compatible with <strong>Firefox 30 - 32</strong></li>
</ul>
<p>&nbsp;</p>
<p>See also <a href="http://blog.getfirebug.com/2014/06/10/firebug-2-0/">list of new features in Firebug 2</a></p>
<p><a href="http://www.softwareishard.com/blog/firebug/firebug-internals-i-data-providers-and-viewers/">Firebug Internals I.</a> </p>
<p><span id="more-964"></span></p>
<h3>Unified Object Rendering</h3>
<p>Firebug (as a web developer tool) is primarily dealing with JS objects coming from the currently debugged page. All these objects are displayed to the user allowing further exploration and inspection. Important aspect of the rendering logic is that an object is always rendered using the same scheme (a template) across Firebug UI. It doesn't matter if the object is displayed in the Console panel, DOM panel or inside the Watch panel when Firebug is halted at a breakpoint. It always look the same and also offers the same set of actions (through the context menu).</p>
<p>Let's see an example. Following three images show how <code>&lt;body&gt;</code> element is displayed in different Firebug panels.</p>
<p>Here is <code>&lt;body&gt;</code> logged in the Console panel.</p>
<p><img alt="" src="http://www.softwareishard.com/architecture/unified-object-rendering/console-panel.png" class="aligncenter" width="520" height="171" /></p>
<p>This screenshot displays <code>&lt;body&gt;</code> in the DOM panel.</p>
<p><img alt="" src="http://www.softwareishard.com/architecture/unified-object-rendering/dom-panel.png" class="aligncenter" width="520" height="171" /></p>
<p>And the last screenshot shows how it looks like in the Watch side panel.</p>
<p><img alt="" src="http://www.softwareishard.com/architecture/unified-object-rendering/watch-panel.png" class="aligncenter" width="520" height="171" /></p>
<p>The element is always rendered using the same template and also the context menu associated with the object offers the same basic actions (plus those related to the current context).</p>
<h3>Architecture</h3>
<p>The architecture behind unified rendering is relatively simple. The logic is based on a repository of templates where every template is associated with JS object type (number, string, etc.). When a panel needs to render an object it gets its type and asks the repository for a template that is associated with it. The template is consequently used to generate HTML markup.</p>
<p>Firebug uses <a href="https://getfirebug.com/wiki/index.php/Domplate">Domplate</a> engine fore templates, but any other templating system could be used instead.</p>
<p><img alt="" src="http://www.softwareishard.com/architecture/unified-object-rendering/rendering-logic.png" class="aligncenter" width="473" height="272" /></p>
<ul>
<li>An object (JS object coming from debugged page content) is logged into the Console panel.</li>
<li>The panel asks the repository to render the object.</li>
<li>Repository gets the right registered template for the object (done usually according to object's type).</li>
<li>Finally, the template renders itself using the original object as data.</li>
</ul>
<h3>Implementation</h3>
<p>Let's yet see a few code examples that show how (simplified) implementation looks like from JavaScript perspective.</p>
<p>Here is how <code>getTemplate</code> can implemented (note that Firebug implementation is a bit different):</p>
<div class="dean_ch" style="white-space: wrap;">getTemplate: <span class="kw2">function</span><span class="br0">&#40;</span>object<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">// Iterate registered templates and return the</span><br />
&nbsp; &nbsp; <span class="co1">// one that supports given object</span><br />
&nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;templates.<span class="me1">length</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> template = templates<span class="br0">&#91;</span>i<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>template.<span class="me1">supportsObject</span><span class="br0">&#40;</span>object<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> template;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> defaultTemplate;<br />
<span class="br0">&#125;</span></div>
<p>An interface of a template object looks like as follows (again simplified).</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">var</span> Template = <br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; className: <span class="st0">&quot;&quot;</span>,</p>
<p>&nbsp; &nbsp; supportsObject: <span class="kw2">function</span><span class="br0">&#40;</span>object<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="kw2">false</span>; <span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; getContextMenuItems: <span class="kw2">function</span><span class="br0">&#40;</span>object<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="br0">&#91;</span><span class="br0">&#93;</span>; <span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; getTooltip: <span class="kw2">function</span><span class="br0">&#40;</span>object<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="kw2">null</span>; <span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; highlightObject: <span class="kw2">function</span><span class="br0">&#40;</span>object, context<span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; inspectObject: <span class="kw2">function</span><span class="br0">&#40;</span>object, context<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="br0">&#125;</span>,<br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<ul>
<li><code>className</code> Every template should have a classname so CSS styles can be associated.</li>
<li><code>supportsObject</code> Used to pick the right template for an object</li>
<li><code>getContextMenuItems</code> Used to get commands that are should be displayed in the context menu.</li>
<li><code>getTooltip</code> Provides a text that is displayed in a tooltip.</li>
<li><code>highlightdObject</code> Can be used to highlight the object within the page if mouse hovers over the object.</li>
<li><code>inspectObject</code> Can be used for further inspection of the object (e.g. selecting the right target panel when the user clicks on the object).</li>
</ul>
<p>See real repository of templates (a template in Firebug is called <em>rep</em>) on <a href="https://github.com/firebug/firebug/blob/firebug1.12/extension/content/firebug/chrome/reps.js">github</a>.</p>
<h3>Extension Points</h3>
<p>The entire concept is also nicely extensible. This is great especially for extension (i.e. Mozilla add-ons) authors that can plug in into the logic and customize it.</p>
<ul>
<li>Extensions can provide and register new templates that are rendering specific object types (coming e.g. from JS libraries like jQuery or EmberJS) and define how objects are rendered across entire UI.</li>
<li>Extensions can also provide a set of actions that can be performed on existing of custom object types.</li>
<li>Extensions can specify new CSS for existing templates and create custom themes.</li>
</ul>
]]></content:encoded>
			</item>
		<item>
		<title>Firebug Internals I. &#8211; Data Providers and Viewers</title>
		<link>http://www.softwareishard.com/blog/firebug/firebug-internals-i-data-providers-and-viewers/</link>
		<comments>http://www.softwareishard.com/blog/firebug/firebug-internals-i-data-providers-and-viewers/#comments</comments>
		<pubDate>Fri, 28 Mar 2014 13:35:35 +0000</pubDate>
		<dc:creator><![CDATA[Honza]]></dc:creator>
				<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Firebug]]></category>
		<category><![CDATA[Planet Mozilla]]></category>

		<guid isPermaLink="false">http://www.softwareishard.com/blog/?p=920</guid>
		<description><![CDATA[One of the achievements of Firebug 2 alpha 1 release has been adoption of new JSD2 API and this task required significant changes and improvements in our code base. Among other things, we have also introduced a new concept that allows to nicely build asynchronously updated UI. There are other concepts in Firebug 2 and [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>One of the achievements of <a href="https://blog.getfirebug.com/2014/03/26/firebug-2-0-alpha-1/">Firebug 2 alpha 1 release</a> has been adoption of new <a href="https://wiki.mozilla.org/Debugger">JSD2 API</a> and this task required significant changes and improvements in our code base. Among other things, we have also introduced a new concept that allows to nicely build asynchronously updated UI.</p>
<p><em>There are other concepts in Firebug 2 and this version is with no doubt the best one we have released. Try it and let us know how it works for you (Firefox 30+ needed).</em></p>
<p>In order to implement remote access to the server side debugger API, Firebug UI needs to know how to deal with asynchronous update. We applied <strong>Viewer Provider</strong> pattern and extended it with support for asynchronous data processing.</p>
<p>If you like using <em>Document View</em>, <em>Model View Controller</em> or similar design patterns to build your code base, you'll probably like <em>Viewer Provider</em> too.</p>
<p>So, follow this post if you are interested to know what <em>Viewer Provider</em> looks like.</p>
<p><span id="more-920"></span></p>
<h3>Viewer Provider</h3>
<p>This design pattern represents a concept of data providers that mediate data access through an unified interface. Providers are usually consumed by <em>Views</em> (or <em>Viewers</em>) that use them to query for data and asynchronously populate their content when results are available.</p>
<p>First let's see simpler, but related <em>Document View</em> pattern:</p>
<p><img alt="" src="http://www.softwareishard.com/architecture/viewer-provider/view-document.png" class="center" /></p>
<ul>
<li><em>View</em> is responsible for data rendering</li>
<li><em>Document</em> represents a data source</li>
</ul>
<p>The problem with this concept is that <em>View</em> needs to know the interface (API) of the <em>Document</em>. This makes it hard for the <em>View</em> to switch to another data source, in other words, it's hard to reuse the same <em>View</em> for other <em>Documents</em>.</p>
<p>An improvement of this simple concept is incorporating a <em>Provider</em> in between the <em>Document</em> and <em>View</em>. The provider knows the <em>Document</em> API and expose them in unified way to the <em>Viewer</em>.</p>
<p><img alt="" src="http://www.softwareishard.com/architecture/viewer-provider/view-provider-document.png" class="center" /></p>
<ul>
<li><em>Provider</em> provides data through unified interface</li>
</ul>
<p>There is typically one provider for one specific data source/document,  but in complex application (like Firebug) there can be even a <a href="https://getfirebug.com/wiki/index.php/Data_Providers_%26_Viewers#Providers">hierarchy</a> of providers.</p>
<p>Having data providers implemented for various data sources means that existing viewers can easily consume any data and can be simply reused.</p>
<p><img alt="" src="http://www.softwareishard.com/architecture/viewer-provider/viewers.png" class="center" /></p>
<p>Here is how <em>Provider</em> interface looks like:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">var</span> Provider =<br />
<span class="br0">&#123;</span><br />
&nbsp; hasChildren: <span class="kw2">function</span><span class="br0">&#40;</span>object<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="kw1">this</span>.<span class="me1">getChildren</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">length</span> &gt; <span class="nu0">0</span>; <span class="br0">&#125;</span>,<br />
&nbsp; getChildren: <span class="kw2">function</span><span class="br0">&#40;</span>object<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="br0">&#91;</span><span class="br0">&#93;</span>; <span class="br0">&#125;</span>,<br />
&nbsp; getLabel: <span class="kw2">function</span><span class="br0">&#40;</span>object, col<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="st0">&quot;&quot;</span>; <span class="br0">&#125;</span>,<br />
&nbsp; getValue: <span class="kw2">function</span><span class="br0">&#40;</span>object, col<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="kw2">null</span>; <span class="br0">&#125;</span>,<br />
<span class="br0">&#125;</span></div>
<ul>
<li><em>hasChildren</em>: used mostly by tree-style viewers that needs to know whether a twisty (+/- icons) should be displayed for specific item or not; It's implementation can be simple, as you can see in the code or optimized for various scenarios.</li>
<li><em>getChildren</em>: returns a list of child objects for the given object</li>
<li><em>getLabel</em>: returns a label for the given object; The label will be directly displayed within the UI (e.g. in a drop down list). The col argument can be used by UI widgets supporting tabular data display (several labels for given object/row).</li>
<li><em>getValue</em> returns a value for the given object </li>
</ul>
<h3>Asynchronous Viewer Provider</h3>
<p>One of the challenges when consuming data is support for asynchronous processing. Especially in case on web applications toady. If you need a data you send XHR and wait for the asynchronous response. Viewer and Provider pattern has a solution fort this too.</p>
<p><img alt="" src="http://www.softwareishard.com/architecture/viewer-provider/asynchronous-viewer-provider.png" class="center" /></p>
<ul>
<li><em>getChildren</em>  returns a <a href="https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Promise.jsm/Promise">Promise</a> instead of a direct list of children. The promise is resolved asynchronously as soon as data is available.</li>
</ul>
<p>The main difference is that <code>getChildren</code> returns a <a href="https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Promise.jsm/Promise">Promise</a>. The solid line (on the image above) represents synchronous data querying, the dashed line represents asynchronous update. The promise object usually comes from the data source and is passed through the provider to the view. Of course, the update happens when queried data are available.</p>
<h3>Online Demo</h3>
<p>You can also check out a simple web application that shows how viewers and providers can be implemented.</p>
<ul>
<li>Source repository on <a href="https://github.com/janodvarko/prototypes/tree/master/async-provider-demo">github</a>
<li>Online demo on <a href="http://www.softwareishard.com/architecture/viewer-provider/demo/">this page</a>
</ul>
<p>The demo application implements the following objects:</p>
<ul>
<li><em>Storage</em> a simple data storage (a document) returning data asynchronously</li>
<li><em>Provider</em> implemented for the <em>Storage</em> above</li>
<li><em>Viewer</em> simple list viewer that is using the <em>Provider</em> above to access data.</li>
</ul>
<p>The application's entry point is <em>main.js</em></p>
<div class="bullet">&nbsp;</div>
<p>&nbsp;<br />
&nbsp;</p>
<p>Read more about Data Provider and how they are <a href="https://getfirebug.com/wiki/index.php/Data_Providers_%26_Viewers#Firebug_Implementation">implemented</a> in <strong>Firebug 2</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.softwareishard.com/blog/firebug/firebug-internals-i-data-providers-and-viewers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Firebug 2: Support for dynamic scripts</title>
		<link>http://www.softwareishard.com/blog/firebug/firebug-2-support-for-dynamic-scripts/</link>
		<comments>http://www.softwareishard.com/blog/firebug/firebug-2-support-for-dynamic-scripts/#comments</comments>
		<pubDate>Thu, 27 Mar 2014 17:34:12 +0000</pubDate>
		<dc:creator><![CDATA[Honza]]></dc:creator>
				<category><![CDATA[Firebug]]></category>
		<category><![CDATA[Planet Mozilla]]></category>
		<category><![CDATA[Release]]></category>

		<guid isPermaLink="false">http://www.softwareishard.com/blog/?p=882</guid>
		<description><![CDATA[Firebug 2 (first alpha) has been released this week and it's time to checkout some of the new features. Note that you need at least Firefox 30 to run it. This brand new version introduces a lot of changes where the most important one is probably the fact that it's based on new Firefox debugging [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://bit.ly/1g1q5n0">Firebug 2</a> (first alpha) has been released this week and it's time to checkout some of the new features. Note that you need at least <strong>Firefox 30</strong> to run it.</p>
<p>This brand new version introduces a lot of changes where the most important one is probably the fact that it's based on new Firefox debugging engine known as <a href="https://wiki.mozilla.org/Debugger">JSD2</a>.</p>
<p>Also Firebug UI has been polished to match Australis theme introduced in Firefox 29.</p>
<p><img class="aligncenter" src="http://www.softwareishard.com/images/posts/firebug2a1/firebug-win.png" alt="" width="520" height="191" /><br />
<span id="more-882"></span></p>
<h3>Dynamically Created Scripts</h3>
<p>Let's see how debugging of dynamically created scripts has been improved in this release and how Firebug UI deals with this common task. We'll cover following dynamic scripts in this post:</p>
<ul>
<li>Inline Event Handlers</li>
<li>Script Element Injection</li>
<li>Function Object</li>
</ul>
<p><em>There are other ways how to create scripts dynamically.</em></p>
<p>&nbsp;</p>
<h4>Inline Event Handlers</h4>
<p>Inline event handlers are little pieces of JavaScript placed within HTML attributes designed to handle basic events like <em>onclick</em>.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="sc3"><span class="re1">&lt;button</span> <span class="re0">onclick</span>=<span class="st0">&quot;testFunction()&quot;</span><span class="re2">&gt;</span></span>Click Me<span class="sc3"><span class="re1">&lt;/button<span class="re2">&gt;</span></span></span></div>
<p>These scripts are compiled dynamically when needed (before executed for the first time). That's why they are considered dynamic and you don't have to see them in the Script location list (until compiled by the browser).</p>
<p><img class="aligncenter" src="http://www.softwareishard.com/images/posts/firebug2a1/inline-event-handler.png" alt="" /></p>
<p>Script's URL is composed dynamically (there is no real URL for dynamic scripts) and event handlers scripts follow this scheme:</p>
<p>&lt;element-name&gt; &lt;attribute-name&gt; &lt;button-label&gt;</p>
<p>If you select the script from the script location menu, you should see the source that is placed within the <em>onclick</em> attribute.</p>
<p><img class="aligncenter" src="http://www.softwareishard.com/images/posts/firebug2a1/inline-event-handler2.png" alt="" /></p>
<p>Of course, you can create a breakpoint as usual. Try live <a href="http://www.softwareishard.com/images/posts/firebug2a1/example1.html">example page</a> if you have Firebug 2 <a href="https://getfirebug.com/releases/firebug/2.0/">installed</a>.</p>
<p>&nbsp;</p>
<h4>Script Element Injection</h4>
<p>Another way how to dynamically compile a piece of script is using <code>&lt;script&gt;</code> element injection.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">var</span> script =<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;var a = 10;<span class="es0">\n</span>&quot;</span> +<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;var b = 10;<span class="es0">\n</span>&quot;</span> +<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;console.log('a + b = %d', a + b);<span class="es0">\n</span>&quot;</span> +<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;//# sourceURL=injected-script.js<span class="es0">\n</span>&quot;</span>;</p>
<p><span class="kw2">var</span> scriptTag = document.<span class="me1">createElement</span><span class="br0">&#40;</span><span class="st0">&quot;script&quot;</span><span class="br0">&#41;</span>;<br />
scriptTag.<span class="me1">textContent</span> = script;<br />
document.<span class="me1">body</span>.<span class="me1">appendChild</span><span class="br0">&#40;</span>scriptTag<span class="br0">&#41;</span>;</div>
<p>Again, you can check out <a href="http://www.softwareishard.com/images/posts/firebug2a1/example2.html">live example</a>.</p>
<p><img class="aligncenter" src="http://www.softwareishard.com/images/posts/firebug2a1/injected-script-element.png" alt="" /></p>
<p>There is couple of things to see:</p>
<ul>
<li>There is one event handler script: <em>button onclick Click Me</em> since we injected the script through a button and its event handler.</li>
<li>There is another dynamic script <em>injected-script.js</em> - this one created using the injected <code>&lt;script&gt;</code> element</li>
<li>Injected script uses custom URL, which is defined within the source using <em>sourceURL</em> comment:<br />
<code>//# sourceURL=injected-script.js</code></p>
<li>If no <code>sourceURL</code> is provided default one is generated (using <code>script</code> element id or xpath)</li>
</ul>
<p><img class="aligncenter" src="http://www.softwareishard.com/images/posts/firebug2a1/injected-script-element2.png" alt="" /></p>
<p>&nbsp;</p>
<h4>Function Object</h4>
<p>Another way how to compile a script dynamically is using JavaScript native <code>Function</code> object.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">var</span> source = <span class="st0">&quot;console.log('a + b = %d', a + b);<span class="es0">\n</span>&quot;</span>;<br />
<span class="kw2">var</span> myFunc = <span class="kw2">new</span> <span class="kw2">Function</span><span class="br0">&#40;</span><span class="st0">&quot;a&quot;</span>, <span class="st0">&quot;b&quot;</span>, source<span class="br0">&#41;</span>;<br />
myFunc.<span class="me1">displayName</span> = <span class="st0">&quot;myFunc&quot;</span>;</p>
<p>myFunc<span class="br0">&#40;</span><span class="nu0">10</span>, <span class="nu0">10</span><span class="br0">&#41;</span>;</div>
<p><img class="aligncenter" src="http://www.softwareishard.com/images/posts/firebug2a1/function-object.png" alt="" /></p>
<ul>
<li>The script URL is generated automatically. The following scheme is used: &lt;parent-page-url&gt; &lt;line-number&gt; "> Function";
</li>
<li>You can't use <em>sourceURL</em> due to a platform <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=981987">bug</a></li>
<li>There is one event handler script</li>
</ul>
<p><img class="aligncenter" src="http://www.softwareishard.com/images/posts/firebug2a1/function-object2.png" alt="" /></p>
<p>Check out <a href="http://www.softwareishard.com/images/posts/firebug2a1/example3.html">live example</a>.</p>
<p class="bullet">
<p>&nbsp;</p>
<p>We want to switch into beta phase soon and it would be great to hear from you about how this version is working for you.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.softwareishard.com/blog/firebug/firebug-2-support-for-dynamic-scripts/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Firebug Tip: Resend HTTP Request</title>
		<link>http://www.softwareishard.com/blog/planet-mozilla/firebug-tip-resend-http-request/</link>
		<comments>http://www.softwareishard.com/blog/planet-mozilla/firebug-tip-resend-http-request/#comments</comments>
		<pubDate>Fri, 06 Sep 2013 10:28:37 +0000</pubDate>
		<dc:creator><![CDATA[Honza]]></dc:creator>
				<category><![CDATA[Firebug Tip]]></category>
		<category><![CDATA[Planet Mozilla]]></category>
		<category><![CDATA[Firebug]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[resend]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.softwareishard.com/blog/?p=844</guid>
		<description><![CDATA[There are many cases when web developer needs to resend an existing HTTP request (executed by the currently debugged page) and test the server back-end or perhaps even a specific web service. Such action can be often repeated, and so the task should be simple and quick. Firebug offers several ways how to resend HTTP [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>There are many cases when web developer needs to resend an existing HTTP request (executed by the currently debugged page) and test the server back-end or perhaps even a specific web service.</p>
<p>Such action can be often repeated, and so the task should be simple and quick.</p>
<p>Firebug offers several ways how to resend HTTP request, read more if you are interested...</p>
<p class="firebugTipsLink">See all <a href="http://www.softwareishard.com/blog/firebug-tips/">Firebug tips</a></p>
<p><span id="more-844"></span></p>
<h3>Resend Action</h3>
<p>The first and obvious way is to use <b>Resend</b> action that is available in the Net and Console panel context menu. It's the simplest method, just right click on an HTTP request in the Net panel or on XHR log in the Console panel and pick the <em>Resend</em> menu item.</p>
<p><img alt="" src="http://www.softwareishard.com/firebug/tips/resend/resend.png" class="aligncenter" width="520" height="174" /></p>
<p>You should see a new request displayed. Both requests will be the same since Firebug preserves headers, posted data, etc.</p>
<p><img alt="" src="http://www.softwareishard.com/firebug/tips/resend/resend2.png" class="aligncenter" width="520" height="281" /></p>
<p>You can use this <a href="http://www.softwareishard.com/firebug/tips/resend/resend.html">test page</a> to try it yourself.</p>
<p>The URL of the webservice is:</p>
<div class="dean_ch" style="white-space: wrap;">http://www.softwareishard.com/firebug/tips/resend/hello.php</div>
<p>...and the implementation looks like as follows:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;Hello &quot;</span>.<span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span><span class="br0">&#93;</span>.<span class="st0">&quot;!&quot;</span>;<br />
<span class="kw1">else</span><br />
&nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;Hello!&quot;</span>;<br />
<span class="kw2">?&gt;</span></div>
<h3>Copy as cURL</h3>
<p>You might prefer OS system command line and its <a href="http://curl.haxx.se/">cURL</a> command line tool.</p>
<p>A simple example first. To get the response from our <em>hello.php</em> service you need to execute:</p>
<div class="dean_ch" style="white-space: wrap;">curl http://www.softwareishard.com/firebug/tips/resend/hello.php</div>
<p>In order to get the cURL command for an existing HTTP request, right click on the request in the Net or Console panel and pick <b>Copy as cURL</b> action. Firebug will copy it with all necessary arguments to the clipboard (preserving headers, etc.)</p>
<p><img alt="" src="http://www.softwareishard.com/firebug/tips/resend/resend3.png" class="aligncenter" width="520" height="214" /></p>
<p>The result in our case is:</p>
<div class="dean_ch" style="white-space: wrap;">curl 'http://www.softwareishard.com/firebug/tips/resend/hello.php' -H 'Host: www.softwareishard.com' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:26.0) Gecko/20100101 Firefox/26.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Referer: http://www.softwareishard.com/firebug/tips/resend/resend.html' --data 'name=Bob'</div>
<h3>Command Editor</h3>
<p>The third option is using Firebug <strong>Command Editor</strong> and execute XHR with pure JavaScript. In this case you might specify headers and other options just as you like it.</p>
<p>Just open Firebug UI and select the Console panel on the page you are debugging.</p>
<p><img alt="" src="http://www.softwareishard.com/firebug/tips/resend/resend4.png" class="aligncenter" width="520" height="252" /></p>
<p>&nbsp;<br />
&nbsp;</p>
<ul>
<li>Would you be interested to have another way to resend a request?</li>
<li>Would it be useful to have also <strong>Copy as Wget</strong>? If yes star <a href="http://code.google.com/p/fbug/issues/detail?id=6645">this issue</a>, so we know how high priority it is for us.
</li>
</ul>
<p>&nbsp;</p>
<div class="bullet">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.softwareishard.com/blog/planet-mozilla/firebug-tip-resend-http-request/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Firebug Tip: getEventListeners() command</title>
		<link>http://www.softwareishard.com/blog/planet-mozilla/firebug-tip-geteventlisteners-command/</link>
		<comments>http://www.softwareishard.com/blog/planet-mozilla/firebug-tip-geteventlisteners-command/#comments</comments>
		<pubDate>Mon, 02 Sep 2013 06:40:47 +0000</pubDate>
		<dc:creator><![CDATA[Honza]]></dc:creator>
				<category><![CDATA[Firebug Tip]]></category>
		<category><![CDATA[Planet Mozilla]]></category>

		<guid isPermaLink="false">http://www.softwareishard.com/blog/?p=806</guid>
		<description><![CDATA[One of the new features introduced in Firebug 1.12 is a new Command Line command called: getEventListeners() &#160; The command returns all the event listeners registered for specific target. The target can be either an element, or another DOM object that accepts event listeners (e.g. window or an XMLHttpRequest). See all Firebug tips Basic Scenario [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>One of the new features introduced in <a href="https://blog.getfirebug.com/2013/08/21/firebug-1-12-0/">Firebug 1.12</a> is a new Command Line command called:</p>
<p><code>getEventListeners()</code><br />
&nbsp;<br />
<em>The command returns all the event listeners registered for specific target. The target can be either an element, or another DOM object that accepts event listeners (e.g. window or an XMLHttpRequest).</em></p>
<p class="firebugTipsLink">See all <a href="http://www.softwareishard.com/blog/firebug-tips/">Firebug tips</a></p>
<p><span id="more-806"></span></p>
<h3>Basic Scenario</h3>
<p>Let's see how the basic usage of the <em>getEventListeners()</em> command looks like. First, here is a test page that registers one click listener for a <em>testElement</em>.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="sc0">&lt;!DOCTYPE html&gt;</span><br />
<span class="sc3"><span class="re1">&lt;html<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;head<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;title<span class="re2">&gt;</span></span></span>getEventListeners()<span class="sc3"><span class="re1">&lt;/title<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/head<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;body<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;div</span> <span class="re0">id</span>=<span class="st0">&quot;testElement&quot;</span><span class="re2">&gt;</span></span>Click Me!<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;script<span class="re2">&gt;</span></span></span><br />
function myClickListener()<br />
{<br />
&nbsp; &nbsp; console.log(&quot;click&quot;);<br />
}<br />
var testElement = document.getElementById(&quot;testElement&quot;);<br />
testElement.addEventListener(&quot;click&quot;, myClickListener, false);<br />
<span class="sc3"><span class="re1">&lt;/script<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/body<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/html<span class="re2">&gt;</span></span></span></div>
<p>The expression we are going to execute on Firebug's Command Line looks like as follows:</p>
<p><code>getEventListeners($("#testElement"))</code></p>
<p>It returns a descriptor object that is logged into the Console panel.</p>
<p><img alt="" src="http://www.softwareishard.com/firebug/tips/geteventlisteners/console-panel.png" class="aligncenter" width="520" height="177" /></p>
<p>If you click the descriptor you'll be navigated to the DOM panel that allows further inspection.</p>
<p><img alt="" src="http://www.softwareishard.com/firebug/tips/geteventlisteners/dom-panel.png" class="aligncenter" width="520" height="204" /></p>
<p>As you can see, there is one click listener registered with the <em>testElement</em> element (the <em>click</em> field is an array containing all registered <em>click</em> listeners). Clicking the <em>myClickListener</em> function navigates you to the Script panel to see its source code and perhaps create a breakpoint for further debugging.</p>
<p><img alt="" src="http://www.softwareishard.com/firebug/tips/geteventlisteners/script-panel.png" class="aligncenter" width="520" height="335" /></p>
<h3>Using getEventListeners() in an expression</h3>
<p>In some cases, we might want to reference the listener function directly in an expression:</p>
<p><code>getEventListeners($("#testElement")).click[0].listener</code></p>
<p>The expression returns directly the handler function that is logged into the Console panel. You'll be navigated to the Script panel directly if you click the return value.</p>
<p>You might also want to manually execute the listener function and e.g. break in the debugger in case you created a breakpoint inside the method.</p>
<p><code>getEventListeners($("#testElement")).click[0].listener()</code></p>
<h3>Event Listeners & Closures</h3>
<p>Some JavaScript libraries that implements API for event listener registration might register their own function and call the original listener through a closure. Let's see a simple example that demonstrates this technique.</p>
<div class="dean_ch" style="white-space: wrap;">observe<span class="br0">&#40;</span>testElement, <span class="st0">&quot;click&quot;</span>, <span class="kw2">function</span> myClickHandler<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;click&quot;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</p>
<p><span class="kw2">function</span> observe<span class="br0">&#40;</span>element, eventType, handler<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">function</span> localHelper<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; handler<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> element.<span class="me1">addEventListener</span><span class="br0">&#40;</span>eventType, localHelper, <span class="kw2">false</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>Executing the following expression on the command line returns <em>localHelper</em> function since it's the registered event handler.</p>
<p><code>getEventListeners($("#testElement")).click[0].listener</code></p>
<p>If you want to log the original listener function <em>myClickHandler</em> - you need to get the <em>handler</em> argument that is accessed by <em>localHelper</em> closure. Next expression shows how variable inside a closure can be accessed (via: <code>.%</code> syntax).</p>
<p><code>getEventListeners($("#testElement")).click[0].listener.%handler</code></p>
<p>This expression returns reference to <em>myClickHandler</em> function.</p>
<p>&nbsp;</p>
<p>You can read more about <a href="https://getfirebug.com/wiki/index.php/Closure_Inspector">Closure Inspector</a> on Firebug wiki.<br />
You can also read wiki page about <a href="https://getfirebug.com/wiki/index.php/GetEventListeners">getEventListeners</a> command.</p>
<div class="bullet">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.softwareishard.com/blog/planet-mozilla/firebug-tip-geteventlisteners-command/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Start with Firebug Lite</title>
		<link>http://www.softwareishard.com/blog/planet-mozilla/how-to-start-with-firebug-lite/</link>
		<comments>http://www.softwareishard.com/blog/planet-mozilla/how-to-start-with-firebug-lite/#comments</comments>
		<pubDate>Wed, 21 Aug 2013 18:30:53 +0000</pubDate>
		<dc:creator><![CDATA[Honza]]></dc:creator>
				<category><![CDATA[Firebug Lite]]></category>
		<category><![CDATA[Planet Mozilla]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://www.softwareishard.com/blog/?p=800</guid>
		<description><![CDATA[FirebugLite is lightweight version of Firebug (the Firefox extension) that does implement only a subset of features (mainly missing the Script and Net panel). It's implemented as pure web application and running in all major browser. Using Firebug lite is quick since it doesn't have to be installed (it's a web app) and it can [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="https://getfirebug.com/firebuglite">FirebugLite</a> is lightweight version of <a href="https://getfirebug.com/">Firebug</a> (the Firefox extension) that does implement only a subset of features (mainly missing the Script and Net panel).</p>
<p>It's implemented as pure web application and running in all major browser.</p>
<p>Using Firebug lite is quick since it doesn't have to be installed (it's a web app) and it can also be injected into an existing page using a bookmarklet.</p>
<p>The next set of screenshots shows how Firebug Lite looks like in various browsers.</p>
<p><img alt="" src="http://www.softwareishard.com/images/posts/start-with-firebuglite/firefox.png" class="aligncenter" width="520" height="300" /></p>
<p>&nbsp;</p>
<p><img alt="" src="http://www.softwareishard.com/images/posts/start-with-firebuglite/chrome.png" class="aligncenter" width="520" height="297" /></p>
<p>&nbsp;</p>
<p><img alt="" src="http://www.softwareishard.com/images/posts/start-with-firebuglite/explorer.png" class="aligncenter" width="520" height="263" /></p>
<p>&nbsp;</p>
<p>Let's see how you can run Firebug Lite within a web page. This post covers four scenarios:</p>
<ul>
<li>Include using &lt;script&gt; element</li>
<li>Run through Bookmarklet</li>
<li>Firebug Lite on iPad</li>
<li>Run as Chrome Extension</li>
</ul>
<p><span id="more-800"></span></p>
<h3>Include using &lt;script&gt; element</h3>
<p>Firebug Lite is pure JS application and so you can include it in your page just like any other JavaScript code. See an example:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="sc0">&lt;!DOCTYPE html&gt;</span><br />
<span class="sc3"><span class="re1">&lt;html<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;head<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;title<span class="re2">&gt;</span></span></span>Test<span class="sc3"><span class="re1">&lt;/title<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;script</span> <span class="re0">src</span>=<span class="st0">&quot;https://getfirebug.com/firebug-lite.js&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">type</span>=<span class="st0">&quot;text/javascript&quot;</span><span class="re2">&gt;</span></span><span class="sc3"><span class="re1">&lt;/script<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/head<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;body<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;div</span> <span class="re0">style</span>=<span class="st0">&quot;color:green&quot;</span><span class="re2">&gt;</span></span>Hello<span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/body<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/html<span class="re2">&gt;</span></span></span></div>
<p>This approach is recommended in cases when you often inspect the same page and you want to have Firebug Lite UI always ready after page load (refresh). You can also download <a href="https://getfirebug.com/releases/lite/latest/firebug-lite.tar.tgz">firebug-lite.js</a> file and run it locally from your web server as follows:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="sc3"><span class="re1">&lt;script</span> <span class="re0">type</span>=<span class="st0">&quot;text/javascript&quot;</span> <span class="re0">src</span>=<span class="st0">&quot;/local/path/to/firebug-lite.js&quot;</span><span class="re2">&gt;</span></span><span class="sc3"><span class="re1">&lt;/script<span class="re2">&gt;</span></span></span></div>
<p>Read <a href="https://getfirebug.com/firebuglite">more</a>.</p>
<h3>Run through Bookmarklet</h3>
<p>You an also inject Firebug Lite into an existing page using the following bookmarklet. </p>
<div class="dean_ch" style="white-space: wrap;">javascript:<span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>F,i,r,e,b,u,g,L,I,T,E<span class="br0">&#41;</span><span class="br0">&#123;</span><span class="kw1">if</span><span class="br0">&#40;</span>F.<span class="me1">getElementById</span><span class="br0">&#40;</span>b<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="kw1">return</span>;E=F<span class="br0">&#91;</span>i+<span class="st0">'NS'</span><span class="br0">&#93;</span>&amp;&amp;F.<span class="me1">documentElement</span>.<span class="me1">namespaceURI</span>;E=E?F<span class="br0">&#91;</span>i+<span class="st0">'NS'</span><span class="br0">&#93;</span><span class="br0">&#40;</span>E,<span class="st0">'script'</span><span class="br0">&#41;</span>:F<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#40;</span><span class="st0">'script'</span><span class="br0">&#41;</span>;E<span class="br0">&#91;</span>r<span class="br0">&#93;</span><span class="br0">&#40;</span><span class="st0">'id'</span>,b<span class="br0">&#41;</span>;E<span class="br0">&#91;</span>r<span class="br0">&#93;</span><span class="br0">&#40;</span><span class="st0">'src'</span>,I+g+T<span class="br0">&#41;</span>;E<span class="br0">&#91;</span>r<span class="br0">&#93;</span><span class="br0">&#40;</span>b,u<span class="br0">&#41;</span>;<span class="br0">&#40;</span>F<span class="br0">&#91;</span>e<span class="br0">&#93;</span><span class="br0">&#40;</span><span class="st0">'head'</span><span class="br0">&#41;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>||F<span class="br0">&#91;</span>e<span class="br0">&#93;</span><span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">appendChild</span><span class="br0">&#40;</span>E<span class="br0">&#41;</span>;E=new%20Image;E<span class="br0">&#91;</span>r<span class="br0">&#93;</span><span class="br0">&#40;</span><span class="st0">'src'</span>,I+L<span class="br0">&#41;</span>;<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span>document,<span class="st0">'createElement'</span>,<span class="st0">'setAttribute'</span>,<span class="st0">'getElementsByTagName'</span>,<span class="st0">'FirebugLite'</span>,<span class="st0">'4'</span>,<span class="st0">'firebug-lite.js'</span>,<span class="st0">'releases/lite/latest/skin/xp/sprite.png'</span>,<span class="st0">'https://getfirebug.com/'</span>,<span class="st0">'#startOpened'</span><span class="br0">&#41;</span>;</div>
<p>Just drag this <a href="javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');">Firebug Lite Link</a> into your Bookmarks toolbar. You can also click the link immediately to test Firebug Lite on this page.</p>
<p>This approach is recommended in cases when you use Firebug Lite for inspecting random pages.</p>
<h3>Firebug Lite on iPad</h3>
<p>One of the most interesting use cases is running Firebug Lite on mobile devices, especially tablets since they have bigger screen (Firebug Lite is not yet optimized for small screens).</p>
<p>Inspecting pages on mobile devices can be faster with Firebug Lite since you don't have to deal with remote debugging settings, setup connection with the PC, etc. All you need is to click a bookmarklet.</p>
<p><a href="http://www.softwareishard.com/images/posts/start-with-firebuglite/iPad.png" rel="lightbox[800]"><img src="http://www.softwareishard.com/images/posts/start-with-firebuglite/iPad-thumb.png" alt="" title="iPad" width="520" height="395" class="aligncenter size-medium wp-image-3366" /></a></p>
<p>Read a post about how to create <a href="http://iosbookmarklets.com/tutorials/firebug-lite-bookmarklet-ipad/">Firebug Lite Bookmarklet for iPad</a>.</p>
<h3>Run as Chrome Extension</h3>
<p>Finally, you can <a href="https://chrome.google.com/webstore/detail/firebug-lite-for-google-c/bmagokdooijbeehmkpknfglimnifench">install Firebug Lite</a> as an extension into Google Chrome browser. </p>
<p>There are benefits over Firebug Lite bookmarlet:</p>
<ul>
<li>Browser toolbar integration</li>
<li>Able to activate Firebug Lite for a particular domain</li>
<li>Firebug Lite will be loaded before all other scripts, allowing it to capture all console calls, and all XHR requests for that page</li>
<li>It is faster to load, because all code and images will be store in the extension's directory in your machine</li>
<li>Will be able to read external resources in the next version</li>
</ul>
<p>Read more about <a href="https://getfirebug.com/releases/lite/chrome/">Firebug Lite on Chrome</a>.</p>
<h3>Resources</h3>
<ul>
<li><a href="https://getfirebug.com/firebuglite">Home Page</a></li>
<li><a href="https://github.com/firebug/firebug-lite">Source Repository</a></li>
<li><a href="https://github.com/firebug/firebug-lite/issues">Issue List</a></li>
<li><a href="https://getfirebug.com/wiki/index.php/Firebug_Lite_FAQ">FAQ Page</a></li>
<li><a href="https://groups.google.com/forum/?fromgroups#!forum/firebug">Newsgroups</a> (shared with Firebug)</li>
</ul>
<p>If you are interested to contribute to the project you can start with reading <a href="http://gal.steinitz.com/blog/2013/07/19/remember-firebug-lite/">Gal's post</a> explaining what you can do. <a href="https://twitter.com/galori">Gal Steinitz</a> is the current Firebug Lite maintainer, so shoot any questions about what's coming up in his direction!</p>
<p>You might also be interested in what <a href="https://blog.getfirebug.com/2013/05/02/future-of-firebug-lite/">the future holds for Firebug Lite</a>.</p>
<div class="bullet">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.softwareishard.com/blog/planet-mozilla/how-to-start-with-firebug-lite/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
