har-export-trigger
har-export-trigger copied to clipboard
devtools.netmonitor.har.enableAutoExportToFile Not Working
Hi,
I'm trying to export HAR files automatically for each page that I visit. I've modified the following options through about:config but Firefox isn't generating any output files.
- devtools.netmonitor.har.enableAutoExportToFile: true
- devtools.netmonitor.har.forceExport: true
- devtools.netmonitor.har.defaultLogDir: /tmp/har/
Having devtools open doesn't help either. I'm testing this on Firefox 63.0.1 on a 64bit Linux machine.
Any help would be appreciated.
Hey @ybahador that functionality was only for the old version https://github.com/firebug/har-export-trigger
You need to get the HAR using JavaScript.
Best Peter
Hey @soulgalore Could you please give a hint or example for getting the HAR using JS? I have tried to programmatically download the HAR. Are there any other ways to do it?
For me works the following code:
window.foo = HAR.triggerExport().then(harLog => { return(harLog); });
return window.foo;
Also don't forget to launch geckodriver with argument --devtools and set option "devtools.toolbox.selectedTool" to "netmonitor" as mentioned here
@vasinkd Thank you very much!
@vasinkd I am not following how that code piece does output. Does that just print it to the log?
I am having difficulty with getting the values to write to a file. I have attempted to use the following code
function download(data, filename, type) {
var file = new Blob([data], {type: type});
if (window.navigator.msSaveOrOpenBlob) // IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
else { // Others
var a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
// Returns a Promise that we access via function above. Call this and store the promise via req=getHAR();
function getHAR() {
window.foo = HAR.triggerExport().then(harLog => { return(harLog); });
return window.foo;
}
//Stores the HAR into var req. Need to write req to a file somehow
req = getHAR()
//This accesses the Promise and tries to write it out.
req.then(function(result) {
console.log(result.entries);
download(result.entries, "test_output", "text");
});
but the downloaded file only contains the following (11 entries are in the network tab)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Any help? Thanks.
Sorry for the long reply. Unfortunately, I can't help you with that since I'm not a JS programmer. These 2 lines of JS code are working pretty good with Python+Selenium.
Also, I should notice that I managed to make it work only with har-export-trigger v. 0.6.0 as it is mentioned here: https://github.com/devtools-html/har-export-trigger/issues/31