automation – Automatize HAR files generation from Google Chrome

automation – Automatize HAR files generation from Google Chrome

The short answer is, there is no way to get at the data you are after directly. The getHAR method is only applicable to extensions meant to extend DevTools itself. The good news is, you can construct the HAR file yourself without too much trouble – this is exactly what phantom.js does.

  1. Start Chrome with remote debugging
  2. Connect to Chrome on the debugging port with a websocket connection
  3. Enable Network debugging, you can also clear cache, etc – see Network API.
  4. Tell the browser to navigate to the page you want to capture, and Chrome will stream all the request meta-data back to you.
  5. Massage the network data into HAR format, ala phantom.js
  6. Profit.

For a head start, I have a post that with sample Ruby code that should you get started with steps 1-4: http://www.igvita.com/2012/04/09/driving-google-chrome-via-websocket-api/

By now theres a browser plugin to do that: https://github.com/devtools-html/har-export-trigger

It uses the WebExtensions DevTools API and I got it to work with both Firefox and Chrome.

See my code for Chrome here: https://github.com/theri/web-measurement-tools/blob/master/load/load_url_using_chrome.py#L175

Automatically installing the plugin in Chrome is a bit more complicated than in Firefox, but feasible – I extracted the plugin archive locally and then link to it in chrome_prefs.json (see same repository).

automation – Automatize HAR files generation from Google Chrome

Not sure if it helps, HAR Recorder uses chrome debug protocol to record HAR and generate a har file (without opening devtools). If you want a variation, you can fork and make changes on it.

Leave a Reply

Your email address will not be published.