<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Brian Grinstead</title>
	
	<link>http://www.briangrinstead.com/blog</link>
	<description />
	<lastBuildDate>Fri, 05 Apr 2013 00:21:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/briangrinstead" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="briangrinstead" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>console.log helper function</title>
		<link>http://www.briangrinstead.com/blog/console-log-helper-function</link>
		<comments>http://www.briangrinstead.com/blog/console-log-helper-function#comments</comments>
		<pubDate>Fri, 05 Apr 2013 00:21:53 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[developer tools]]></category>
		<category><![CDATA[devtools]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=1217</guid>
		<description><![CDATA[I have often found it tricky to get a &#8216;just-right&#8217; console.log wrapper in JavaScript. I would prefer to just type log, but writing a wrapper function is a little trickier than at first glance. A variation of this used to exist in the HTML5 Boilerplate plugin.js but is now missing. I have two versions &#8211; [...]]]></description>
				<content:encoded><![CDATA[<p>I have often found it tricky to get a &#8216;just-right&#8217; console.log wrapper in JavaScript.  I would prefer to just type <code>log</code>, but writing a wrapper function is a little trickier than at first glance.  A variation of this used to exist in the <a href='https://github.com/h5bp/html5-boilerplate/blob/master/js/plugins.js'>HTML5 Boilerplate plugin.js</a> but is now missing.  </p>
<p>I have two versions &#8211; one is bigger, and is intended for an application &#8211; it stubs out console methods when they don&#8217;t exist, and exposes a log function to the window.  The second is portable &#8211; it is meant for use inside of plugins.</p>
<p>The neat thing about this technique is that this preserves the original line of code inside of the console.log statement, rather than the line in which the log function is declared.</p>
<hr />
<p>The <a href='https://gist.github.com/bgrins/5108712'>code is in a gist</a>, which is also embedded below:</p>
<p><script src="https://gist.github.com/bgrins/5108712.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/console-log-helper-function/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Devtools Colorpicker Palette</title>
		<link>http://www.briangrinstead.com/blog/devtools-colorpicker-palette</link>
		<comments>http://www.briangrinstead.com/blog/devtools-colorpicker-palette#comments</comments>
		<pubDate>Sun, 03 Feb 2013 04:08:51 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[colorpicker]]></category>
		<category><![CDATA[developer tools]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=1210</guid>
		<description><![CDATA[I&#8217;m still trying to figure out how to get a list of all the colors in use on a page from within devtools, but I&#8217;ve been hacking together a little demo with a custom Web Inspector frontend that loads a color palette on the side. When you click one of the swatches, it sets the [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m still trying to figure out how to get a list of all the colors in use on a page from within devtools, but I&#8217;ve been hacking together a little demo with a custom Web Inspector frontend that loads a color palette on the side.</p>
<p>When you click one of the swatches, it sets the current color of the element.  The idea is that it would include all the colors in your page, maybe ordered by most used.  Possibly could even get more advanced and suggest a set of complementary or analagous colors based on your current selection.</p>
<div id="attachment_1211" class="wp-caption aligncenter" style="width: 343px"><a href="http://briangrinstead.com/files/BCDmb7BCQAASDvW.png"><img src="http://briangrinstead.com/files/BCDmb7BCQAASDvW.png" alt="A prototype implementation of a palette using color swatches within devtools" width="333" height="301" class="size-full wp-image-1211" /></a><p class="wp-caption-text">A prototype implementation of a palette using color swatches within devtools</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/devtools-colorpicker-palette/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery UI 1.9 Boilerplate</title>
		<link>http://www.briangrinstead.com/blog/jquery-ui-1-9-boilerplate</link>
		<comments>http://www.briangrinstead.com/blog/jquery-ui-1-9-boilerplate#comments</comments>
		<pubDate>Wed, 17 Oct 2012 20:05:31 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery-ui]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=1193</guid>
		<description><![CDATA[jsbin has made having to remember some of these links less important. However, with jQuery UI 1.9 coming out, there are some CDN links that aren&#8217;t working. Here is the updated boilerplate I use to quickly test out a jQuery UI project. If all goes well, you should have a dialog that you can drag [...]]]></description>
				<content:encoded><![CDATA[<p><a href='http://jsbin.com'>jsbin</a> has made having to remember some of these links less important.  However, with <a href='http://blog.jqueryui.com/2012/10/jquery-ui-1-9-0/'>jQuery UI 1.9 coming out</a>, there are some CDN links that aren&#8217;t working.  Here is the updated boilerplate I use to quickly test out a jQuery UI project.  If all goes well, you should have a dialog that you can drag around and resize.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;&lt;/title&gt;
&nbsp;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css&quot;&gt;
&nbsp;
  &lt;script type=&quot;text/javascript&quot; src=&quot;http://code.jquery.com/jquery-1.8.2.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.0/jquery-ui.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&nbsp;
  &lt;style type=&quot;text/css&quot;&gt;
    #modal {
	 background: orange;
    }
  &lt;/style&gt;
&nbsp;
  &lt;script type='text/javascript'&gt;
    $(function() {
        $(&quot;#modal&quot;).dialog({ title: &quot;It works&quot; })
    });
  &lt;/script&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&lt;div id='modal'&gt;jQuery UI!&lt;/div&gt;
&lt;/body&gt;
&nbsp;
&lt;/html&gt;</pre></div></div>

<p>As a bonus, here is the <a href='http://jsbin.com/unayan'>markup in jsbin</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/jquery-ui-1-9-boilerplate/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DevTools Feature Request – console.scope()</title>
		<link>http://www.briangrinstead.com/blog/devtools-feature-request-console-scope</link>
		<comments>http://www.briangrinstead.com/blog/devtools-feature-request-console-scope#comments</comments>
		<pubDate>Thu, 13 Sep 2012 01:57:02 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[devtools]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=1175</guid>
		<description><![CDATA[Sometimes I just want to see all (or many) of the variables inside of the function, and it can be a bit of work to copy all of the variables into the console.log() call when you know that you are just going to delete the line afterwards anyway. It would be great to have a [...]]]></description>
				<content:encoded><![CDATA[<p>Sometimes I just want to see all (or many) of the variables inside of the function, and it can be a bit of work to copy all of the variables into the console.log() call when you know that you are just going to delete the line afterwards anyway.  </p>
<p>It would be great to have a console function that handles this.  It would be called <strong>console.scope</strong>.  When you call <code>console.scope()</code> it would act similarly to <code>console.trace()</code>, except instead of seeing the call stack in the console, you would see the same thing that you see in the &#8216;Scope Variables&#8217; panel when inside a breakpoint in the Sources Panel (see images).</p>
<p><a href="http://briangrinstead.com/files/console-scope.png"><img src="http://briangrinstead.com/files/console-scope.png" alt="" title="console-scope" width="531" height="115" class="aligncenter size-full wp-image-1177" /></a></p>
<p><a href="http://briangrinstead.com/files/scope-variables.png"><img src="http://briangrinstead.com/files/scope-variables.png" alt="" title="scope-variables" width="412" height="565" class="aligncenter size-full wp-image-1178" /></a></p>
<p>I have also opened a <a href='https://groups.google.com/forum/?fromgroups#!topic/google-chrome-developer-tools/wKEMpKjXR7s'>thread about this on the devtools mailing list</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/devtools-feature-request-console-scope/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>TinyColor On npm</title>
		<link>http://www.briangrinstead.com/blog/tinycolor-on-npm</link>
		<comments>http://www.briangrinstead.com/blog/tinycolor-on-npm#comments</comments>
		<pubDate>Wed, 12 Sep 2012 18:54:22 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[microframework]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=1114</guid>
		<description><![CDATA[I have published my TinyColor package to the npm repository &#8211; https://npmjs.org/package/tinycolor2. Unfortunately it is called tinycolor2 since tinycolor was already taken. After running npm install tinycolor2 You can use tinycolor like so: var tinycolor = require&#40;&#34;./tinycolor&#34;&#41;; console.log&#40;tinycolor&#40;&#34;red&#34;&#41;.toHex&#40;&#41;&#41;; See the project homepage or the README for more info.]]></description>
				<content:encoded><![CDATA[<p>I have published my <a href='https://github.com/bgrins/TinyColor/'>TinyColor</a> package to the npm repository &#8211; <a href='https://npmjs.org/package/tinycolor2'>https://npmjs.org/package/tinycolor2</a>.  Unfortunately it is called <em>tinycolor2</em> since tinycolor was already taken.</p>
<p>After running</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">npm install tinycolor2</pre></div></div>

<p>You can use tinycolor like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> tinycolor <span style="color: #339933;color: #000000;">=</span> require<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">&quot;./tinycolor&quot;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;color: #000000;">&#40;</span>tinycolor<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">&quot;red&quot;</span><span style="color: #009900;color: #000000;">&#41;</span>.<span style="color: #660066;">toHex</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span></pre></div></div>

<p>See the <a href='http://bgrins.github.com/TinyColor/'>project homepage</a> or the <a href='https://github.com/bgrins/TinyColor/'>README</a> for more info.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/tinycolor-on-npm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Devtools Colorpicker</title>
		<link>http://www.briangrinstead.com/blog/devtools-colorpicker</link>
		<comments>http://www.briangrinstead.com/blog/devtools-colorpicker#comments</comments>
		<pubDate>Mon, 02 Jul 2012 13:35:40 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[colorpicker]]></category>
		<category><![CDATA[developer tools]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=1058</guid>
		<description><![CDATA[It is great that so many important platforms that we use on the web are open source, and open to contributions from anyone. It took a lot of work, but it was worth it. I&#8217;ve been doing some web design work recently, and love how much easier it is to play with different colors in [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://briangrinstead.com/files/devtools-colorpicker-full.png"><img src="http://briangrinstead.com/files/devtools-colorpicker-full.png" alt="" title="Colorpicker inside of devtools - inspector panel" width="800" class="aligncenter size-medium wp-image-1100" /></a></p>
<p>It is great that so many important platforms that we use on the web are open source, and open to contributions from anyone.</p>
<p>It took <a href='http://www.briangrinstead.com/blog/chrome-developer-tools-colorpicker-implementation'>a lot of work</a>, but it was worth it.  I&#8217;ve been doing some web design work recently, and love how much easier it is to play with different colors in a design.</p>
<p>Now I&#8217;m thinking of different ways that design work could be further improved with the colorpicker.  A couple of ideas right now: (a) an eyedropper to select a color from the screen and (b) a color palette consisting of currently used and recommended colors.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/devtools-colorpicker/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DevTools Feature Request: Show Stack Trace In Event Listeners</title>
		<link>http://www.briangrinstead.com/blog/devtools-feature-request-show-stack-trace-in-event-listeners</link>
		<comments>http://www.briangrinstead.com/blog/devtools-feature-request-show-stack-trace-in-event-listeners#comments</comments>
		<pubDate>Thu, 21 Jun 2012 14:57:38 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[devtools]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=1057</guid>
		<description><![CDATA[I was asked a question in my DevTools talk at ComoRichWeb this month. Q: How do the event listeners work when the events are bound with jQuery? A: Not well. I rarely use that section when using a framework to bind events, because the event listeners never point back to the actual function being bound [...]]]></description>
				<content:encoded><![CDATA[<p>I was asked a question in my <a href='http://www.briangrinstead.com/blog/devtools-talk-slides-and-links'>DevTools talk</a> at ComoRichWeb this month.</p>
<blockquote><p>
<em>Q: How do the event listeners work when the events are bound with jQuery?</em></p>
<p>A: <strong>Not well</strong>.  I rarely use that section when using a framework to bind events, because the event listeners never point back to the actual function being bound &#8211; instead they link to the jQuery source.
</p></blockquote>
<p><a href="http://briangrinstead.com/files/eventlisteners.png"><img src="http://briangrinstead.com/files/eventlisteners.png" alt="" title="eventlisteners" width="622" height="154" class="aligncenter size-full wp-image-1061" /></a></p>
<p>The info you see on event listeners bound with jQuery is not very useful.  It shows you the actual function where the events were bound (which is inside of the jQuery source).  </p>
<p>Open up this <a href='http://jsfiddle.net/bgrins/Z8NuL/show/'>simple event listener test case</a> in devtools (inspect the button and view event listeners) to see what I mean.</p>
<h3>What Information Do You Want From Event Listeners?</h3>
<p>What I am actually interested in is the actual callback that jQuery is adding.  Of course devtools shouldn&#8217;t have to handle jQuery (or other frameworks) specifically, but what if it showed <strong>the callstack that caused the event to be bound</strong>?  </p>
<p>So, by setting a breakpoint to the actual event event binding, here is what I got.  This is what I am actually interested in:</p>
<p><a href="http://briangrinstead.com/files/callstack1.png"><img src="http://briangrinstead.com/files/callstack1.png" alt="" title="callstack" width="418" height="153" class="aligncenter size-full wp-image-1064" /></a></p>
<h3>Solution?</h3>
<p>And putting my photo editing skills to the test, here is what it could look like (of course, this should be styled consistently).  Clicking on one of the entries in the callstack would take you into the relevant place in the scripts panel.</p>
<p><a href="http://briangrinstead.com/files/callstack-within-eventlisteners.png"><img src="http://briangrinstead.com/files/callstack-within-eventlisteners.png" alt="" title="callstack-within-eventlisteners" width="639" height="387" class="aligncenter size-full wp-image-1065" /></a></p>
<p>This would be ideal.  Is this even possible?  Or there is an existing or better way to get around this that I don&#8217;t know about?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/devtools-feature-request-show-stack-trace-in-event-listeners/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>DevTools Talk – Slides and Links</title>
		<link>http://www.briangrinstead.com/blog/devtools-talk-slides-and-links</link>
		<comments>http://www.briangrinstead.com/blog/devtools-talk-slides-and-links#comments</comments>
		<pubDate>Thu, 21 Jun 2012 14:31:00 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[developer tools]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=1050</guid>
		<description><![CDATA[I presented on using Chrome Developer Tools at ComoRichWeb, a web developer user group in Columbia, MO on June 20th. Here are the slides and some other links: Slides and Demo DevTools, Part II Slides Color picking demo to play around with devtools Other Links Mentioned in the Talk Source Maps Article Remote Debugging on [...]]]></description>
				<content:encoded><![CDATA[<p>I presented on using Chrome Developer Tools at ComoRichWeb, a <a href='http://comorichweb.posterous.com/'>web developer user group in Columbia, MO</a> on June 20th.  Here are the slides and some other links:</p>
<h3>Slides and Demo</h3>
<ul>
<li>
<a href='http://briangrinstead.com/devtools2/'>DevTools, Part II Slides</a>
</li>
<li>
<a href='http://briangrinstead.com/devtools2/demo/'>Color picking demo to play around with devtools</a>
</li>
</ul>
<h3>Other Links Mentioned in the Talk</h3>
<ul>
<li>
<a href='http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/'>Source Maps Article</a>
</li>
<li>
<a href='https://developers.google.com/chrome/mobile/docs/debugging'>Remote Debugging on Android (apparently also coming to iOS 6)</a>
</li>
<li>
<a href='http://code.google.com/chrome/devtools/docs/overview.html'>Devtools Documentation</a>
</li>
<li>
<a href='https://github.com/h5bp/html5-boilerplate/blob/master/js/plugins.js'>log() function wrapper from HTML5 Boilerplate</a>
</li>
</ul>
<p>We had a good turnout last night, was glad to get a chance to share some front-end development tips with local developers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/devtools-talk-slides-and-links/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FileReaderSync</title>
		<link>http://www.briangrinstead.com/blog/filereadersync</link>
		<comments>http://www.briangrinstead.com/blog/filereadersync#comments</comments>
		<pubDate>Fri, 01 Jun 2012 20:00:59 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[filereader]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=968</guid>
		<description><![CDATA[I have been working on updating the FileReader.js JavaScript file reading library lately to help out with a few different projects. This library has provided a quick way to get started with reading files on a few different projects, like mothereffinganimatedgif.com and Instant Sprite. One thing I noticed was that there is a FileReaderSync API, [...]]]></description>
				<content:encoded><![CDATA[<p>I have been working on updating the <a href='http://bgrins.github.com/filereader.js'>FileReader.js</a> JavaScript file reading library lately to help out with a few different projects.  This library has provided a quick way to get started with reading files on a few different projects, like <a href='http://mothereffinganimatedgif.com/'>mothereffinganimatedgif.com</a> and <a href='http://instantsprite.com'>Instant Sprite</a>.</p>
<p>One thing I noticed was that there is a <a href='http://www.w3.org/TR/FileAPI/#FileReaderSync'>FileReaderSync</a> API, meant for loading files synchronously.</p>
<p>You might wonder <em>why on earth would you want to load a file synchronously in your browser</em> &#8211; that seems like it could block the entire UI until the file is loaded!  It turns out you <strong>can&#8217;t</strong>, at least not in the normal <code>window</code> context.  FileReaderSync only exists inside of the context of a WebWorker:</p>
<p><a href="http://briangrinstead.com/files/filereadersync.png"><img src="http://briangrinstead.com/files/filereadersync.png" alt="" title="FileReaderSync Is Not Defined" width="359" height="55" class="aligncenter size-full wp-image-971" /></a></p>
<h3>Implementation</h3>
<p>View a <a href='http://jsfiddle.net/bgrins/7DjCP/' class='btn'>A working JS Fiddle using FileReaderSync</a>.</p>
<p>I also wrote about <a href='http://www.briangrinstead.com/blog/load-web-workers-without-a-javascript-file'>how to load web workers without a JavaScript file</a>, but this technique works just fine using a normal external reference.</p>
<h4>markup</h4>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;input type='file' id='files' multiple onchange='handleFileSelect()' /&gt;</pre></div></div>

<h4>page javascript</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;color: #0000FF;">function</span> processFiles<span style="color: #009900;color: #000000;">&#40;</span>files<span style="color: #339933;color: #000000;">,</span> cb<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
    <span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> syncWorker <span style="color: #339933;color: #000000;">=</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">new</span> Worker<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">'worker.js'</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
    syncWorker.<span style="color: #660066;">onmessage</span> <span style="color: #339933;color: #000000;">=</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>e<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
        cb<span style="color: #009900;color: #000000;">&#40;</span>e.<span style="color: #660066;">data</span>.<span style="color: #660066;">result</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
    <span style="color: #009900;color: #000000;">&#125;</span><span style="color: #339933;color: #000000;">;</span>
&nbsp;
    Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">forEach</span>.<span style="color: #660066;">call</span><span style="color: #009900;color: #000000;">&#40;</span>files<span style="color: #339933;color: #000000;">,</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>file<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
        syncWorker.<span style="color: #660066;">postMessage</span><span style="color: #009900;color: #000000;">&#40;</span>file<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
    <span style="color: #009900;color: #000000;">&#125;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
<span style="color: #009900;color: #000000;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;color: #0000FF;">function</span> handleFileSelect<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
    <span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> files <span style="color: #339933;color: #000000;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">'files'</span><span style="color: #009900;color: #000000;">&#41;</span>.<span style="color: #660066;">files</span><span style="color: #339933;color: #000000;">;</span>
    processFiles<span style="color: #009900;color: #000000;">&#40;</span>files<span style="color: #339933;color: #000000;">,</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>src<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
        <span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> img <span style="color: #339933;color: #000000;">=</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">new</span> Image<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
        img.<span style="color: #660066;">src</span> <span style="color: #339933;color: #000000;">=</span> src<span style="color: #339933;color: #000000;">;</span>
        document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;color: #000000;">&#40;</span>img<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
    <span style="color: #009900;color: #000000;">&#125;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
<span style="color: #009900;color: #000000;">&#125;</span></pre></div></div>

<h4>worker.js</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">self.<span style="color: #660066;">addEventListener</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">'message'</span><span style="color: #339933;color: #000000;">,</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>e<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span> 
    <span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> data<span style="color: #339933;color: #000000;">=</span>e.<span style="color: #660066;">data</span><span style="color: #339933;color: #000000;">;</span> 
    <span style="color: #000066; font-weight: bold;color: #0000FF;">try</span> <span style="color: #009900;color: #000000;">&#123;</span> 
        <span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> reader <span style="color: #339933;color: #000000;">=</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">new</span> FileReaderSync<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span> 
        postMessage<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #009900;color: #000000;">&#123;</span> 
            result<span style="color: #339933;color: #000000;">:</span> reader.<span style="color: #660066;">readAsDataURL</span><span style="color: #009900;color: #000000;">&#40;</span>data<span style="color: #009900;color: #000000;">&#41;</span>
        <span style="color: #009900;color: #000000;">&#125;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
   <span style="color: #009900;color: #000000;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #0000FF;">catch</span><span style="color: #009900;color: #000000;">&#40;</span>e<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #009900;color: #000000;">&#123;</span> 
        postMessage<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #009900;color: #000000;">&#123;</span> 
            result<span style="color: #339933;color: #000000;">:</span><span style="color: #3366CC;color: #808080;">'error'</span>
        <span style="color: #009900;color: #000000;">&#125;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span> 
   <span style="color: #009900;color: #000000;">&#125;</span> 
<span style="color: #009900;color: #000000;">&#125;</span><span style="color: #339933;color: #000000;">,</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">false</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span></pre></div></div>

<p>The <a href='http://jsfiddle.net/bgrins/7DjCP/'>jsFiddle demo</a> is a little more complicated than this, since it handles checking for support and an inline worker.</p>
<h3>Gotchas</h3>
<p>Something that was a little weird is that since you can&#8217;t detect support from the main window, I need to spawn off a worker to post the message of whether it supports FileReaderSync.  See a <a href='http://jsfiddle.net/bgrins/tTktH/'>jsFiddle to detect FileReaderSync support</a>.  There may be a better way to do this, but I don&#8217;t know of it.</p>
<p>This can be pretty complicated, but I have been tying it all into the <a href='http://bgrins.github.com/filereader.js/'>filereader.js plugin</a>, to make reading with <code>FileReaderSync</code> just an option along with the standard <code>FileReader</code></p>
<h3>Performance</h3>
<p>It&#8217;s hard for me to accurately measure the performance.  On one hand, the <strong>FileReaderSync</strong>  seems to load the images in a slower time per image (measured in milliseconds).  I assume that this is due to the overhead and message passing with the worker, or possibly because it is a newer implementation.  </p>
<p>However, on large images and videos, it definitely feels like the UI does not lock up as much when processing the files.</p>
<h3>Purpose</h3>
<p>I feel like maybe part of the point of this API is when you want to some heavy lifting with the file after it is loaded but still <em>inside the worker</em>, which isn&#8217;t currently supported in FileReader.js.  I could imagine ways this use case could be supported though (maybe by passing in a <code>process()</code> function as a string that the worker could call?</p>
<p>Check out the <a href='http://bgrins.github.com/filereader.js'>FileReader.js demo</a> and see if you can tell a difference!  I&#8217;d love to get any kinks worked out and get some feedback &#8211; I have been thinking of setting up a js-file-boilerplate project on Github to tie together a bunch of this functionality in a sample project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/filereadersync/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging Web Workers</title>
		<link>http://www.briangrinstead.com/blog/debugging-web-workers</link>
		<comments>http://www.briangrinstead.com/blog/debugging-web-workers#comments</comments>
		<pubDate>Tue, 29 May 2012 17:55:30 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[developer tools]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=994</guid>
		<description><![CDATA[While working on FileReader.js Web Worker file processing with FileReaderSync, I needed to figure out what was going on with the script inside a web worker. It can be very difficult to track down errors without standard developer tool support, like logging and debugging. Luckily, in Chrome Devtools, this is possible. How to do it [...]]]></description>
				<content:encoded><![CDATA[<p>While working on FileReader.js Web Worker file processing with FileReaderSync, I needed to figure out what was going on with the script inside a web worker.  It can be very difficult to track down errors without standard developer tool support, like logging and debugging.  Luckily, in Chrome Devtools, this is possible.</p>
<h3>How to do it</h3>
<p>It can be a little tricky to find, but click over to the &#8216;Scripts&#8217; panel, and expand the &#8216;Workers&#8217; accordion on the right.  Then check the &#8216;Pause on Start&#8217; checkbox and you will enter the debugging mode once the worker gets fired up.  Here is a screenshot of the relevant checkbox:</p>
<p><a href="http://briangrinstead.com/files/Pause-On-Web-Worker.png"><br />
<img src="http://briangrinstead.com/files/Pause-On-Web-Worker.png" alt="" title="Pause On Web Worker" width="1426" class="aligncenter size-full wp-image-995" /></a></p>
<h3>Screencast</h3>
<p>Here is a screencast of me playing with this feature:</p>
<p><object id="scPlayer"  width="950" height="520" type="application/x-shockwave-flash" data="http://content.screencast.com/users/bgrins/folders/Jing/media/979ffd3d-1503-4e49-9828-b9b0496d0024/jingswfplayer.swf" ><param name="movie" value="http://content.screencast.com/users/bgrins/folders/Jing/media/979ffd3d-1503-4e49-9828-b9b0496d0024/jingswfplayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /><param name="flashVars" value="thumb=http://content.screencast.com/users/bgrins/folders/Jing/media/979ffd3d-1503-4e49-9828-b9b0496d0024/FirstFrame.jpg&#038;containerwidth=950&#038;containerheight=520&#038;content=http://content.screencast.com/users/bgrins/folders/Jing/media/979ffd3d-1503-4e49-9828-b9b0496d0024/00000012.swf&#038;blurover=false" /><param name="allowFullScreen" value="true" /><param name="scale" value="showall" /><param name="allowScriptAccess" value="always" /><param name="base" value="http://content.screencast.com/users/bgrins/folders/Jing/media/979ffd3d-1503-4e49-9828-b9b0496d0024/" />Unable to display content. Adobe Flash is required.</object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/debugging-web-workers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: www.briangrinstead.com @ 2013-04-25 07:11:52 -->
