title: Automatize HAR files generation from Google Chrome
body: <p>Basically what I need is a way to automatize the <em>result</em> of the following operations:</p>
  
  <ol>
  <li><p>open a new tab;</p></li>
  <li><p>open the Network tab in the developer tools;</p></li>
  <li><p>load an URL;</p></li>
  <li><p>select "Save All as HAR".</p></li>
  </ol>
  
  <p>Often, proposed solutions involves the use of <a href="http://phantomjs.org/">PhantomJS</a>, <a href="http://opensource.webmetrics.com/browsermob-proxy/">browsermob-proxy</a>, or <a href="https://github.com/andrewf/pcap2har">pcap2har</a>; those won't fit my case since I need to work with <a href="http://dev.chromium.org/spdy">SPDY</a> traffic.</p>
  
  <p>I tried to dive into the <a href="http://developer.chrome.com/stable/extensions/api_index.html">Google Chrome Extensions API</a> and indeed I managed to automatize some tasks, but still no luck for what concerns the HAR files generation. Now <a href="http://developer.chrome.com/stable/extensions/devtools.network.html#method-getHAR">this method</a> is particularly promising but I still can't figure out how would I use it.</p>
  
  <p>In other words, I need something like <a href="https://developers.google.com/speed/articles/spdy-for-mobile">this experiment</a> from <em>the Google guys</em>. Note the following:</p>
  
  <blockquote>
    <p>We used Chrome's <a href="https://developers.google.com/chrome-developer-tools/docs/remote-debugging">remote debugging interface</a> with a custom client that starts up the browser on the phone, clears its cache and other state, initiates a web page load, and receives the Chrome developer tools messages to determine the page load times and other performance metrics.</p>
  </blockquote>
  
  <p>Any ideas?</p>
  
  <hr>
  
  <h1>Solution</h1>
  
  <p>For the curious, I ended up with a Node.js module that automates such kind of tests: <a href="https://github.com/cyrus-and/chrome-har-capturer">chrome-har-capturer</a>. This also gave me the opportunity to dig deeper into the <a href="https://developer.chrome.com/devtools/docs/protocol/1.1/index">Remote Debugging Protocol</a> and to write a lower-level Node.js interface for general-purpose Chrome automation: <a href="https://github.com/cyrus-and/chrome-remote-interface">chrome-remote-interface</a>.</p>