I have been working on a firebug-gaps feature related to HAR export
(exporting data collected by the Network panel into HTTP Archive Format).
The manual export (copy to clipboard and save as HAR) is quite
straightforward and there is already a working patch waiting for a review
(Bug 1167080).
The second part of the feature is support for automation. It should be
possible to automate HAR exporting using e.g. Selenium. For instance, run a
test suite and get HAR data for every loaded test page automatically. All
HAR data can be consequently analyzed to figure out also page load
peformance during testing. You can follow bug 1167080 (there is already a
patch for it).
I have solved this by designing a simple HAR API. If a preference is set
(new pref introduced for the HAR feature) the HAR API is exposed to the
content.
There are two methods:
HAR.triggerExport() : allows triggering HAR export at any time during the
page life time.
HAR.clear() : allows clearing content of the Network panel (to avoid
duplicated data exports).
Here is an example of a script that can automatically trigger the export
(from within the content scope):
// myWebApplication.html
// Helper function that exports data collected by the Network panel
// and then clears its content.
function onExportHar(e) {
var options = {
fileName: "myFile.har", // Save into this file
getData: true, // get also HAR string back
}
HAR.triggerExport(options).then(result) {
// Log HAR string into the console
console.log(result.data);
// Data exported, clean up the Network panel
HAR.clear();
});
}
addEventListener("load", onExportHar, true);
---
This approach is simple and flexible enough to fully automate the export.
I have already collected some feedback here:
https://groups.google.com/forum/#!topic/firebug/u3nbmQfiMHk
Do you have any opinions about the approach?
Could it be yet improved/simplified?
Honza