Andy Davies

Web Performance Consultant

Generating HAR Files for iOS Safari

If you want to generate page load waterfalls for iOS Safari the current options are Mobitest / WebPageTest or Safari on OSX.

Mobitest and WebPageTest are great tools (essentially the same tool underneath) that I often use but they have a few limitations:
- there's a limited number of test locations so latency can complicate testing
- uses a UIWebView so any javascript in the pages doesn't have access to the JIT

Safari on OSX is OK but there seems to be no way of generating a HAR file from the waterfall view in developer tools.

These limitations sometimes frustrate me so I decided to write a generator that creates HAR files from Safari running on the iOS Simulator (actual physical iPhones and iPad support will hopefully come too).

The generator is a node application that uses the Safari remote debugging protocol to talk to Safari running on the iOS simulator.

Although the debugging commands for Safari are essentially the same as Chrome's they're wrapped up as binary plists in an undocumented RPC protocol.

If you want to know more about the communications side node-iosdriver is the repository you need.

Installation

  1. Clone ios-har-builder
  2. Run npm install to install dependencies

Usage

Load the iOS Simulator, launch Safari and then run the HAR builder from the OSX command line e.g.

bin/ios-har-builder -o example.har https://m.guardian.co.uk

There should now be a HAR file ready for import into HAR viewer etc.

Issues

It's fresh code, and a bit rough and ready in places so I doubt these are the only issues, if you come across any more feel free to raise an issue on GitHub or better still send me a pull request!

  • Cookies aren't currently supported in the exported HAR file (this is just a matter of writing the code)
  • Code needs cleaning up and refactoring in several places, particularly around the network events in client.js
  • Host and Port parameters don't work
  • Only works on iOS Simulator (for now)
  • Validation needs to be disabled to display the watefalls in the HAR viewer
  • Limited timing information due to the lack of resource timing in Safari

Credits

Tom Ashworth and Remy Sharp at Left Logic did a lot of the work involved with being able to communicate with Safari on iOS.

I was going to start from the netsniff.js example included with phantomjs but then Andrea Cardaci released chrome-har-capturer which saved me some time.

For now ios-har-builder is a separate fork as there are some differences in behaviour between Chrome and Safari e.g. lack of navigation / resource timing in Safari, Safari wraps the WebKit debug protocol in RPC etc.

Comments