You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jan Odvarko edited this page Nov 4, 2015
·
10 revisions
Take a look at the following example scripts showing how to use HAR API.
Do you have an issue with any of the following examples? Please file a report.
All examples bellow assume that the security token in your Firefox profile is set to test. This token needs to be set in extensions.netmonitor.har.contentAPIToken preference.
Get HAR Data
This script shows how to trigger HAR export and get JSON data back (no local file created).
var options = {
token: "test", // Value of the token in your preferences
getData: true, // True if you want to also get HAR data as a string in the callback
};
HAR.triggerExport(options).then(result => {
console.log(result.data);
});
Clear
It's possible to clear collected data at any time and export only new HTTP activity.
HAR.clear({token: "test"});
Save To File
This example shows how to trigger HAR export and save the log automatically in a local *.har file. The default target directory is <firefox-profile-dir>/har/logs. You can provide different directory path in devtools.netmonitor.har.defaultLogDir preference.
File name can use format string to have better control over the formatting of the generated file name.
var options = {
token: "test",
fileName: "my test har file %Y, %H:%M:%S" // Name of the file with format string
};
HAR.triggerExport(options).then(result => {
// The local file is available now
});