har-export-trigger icon indicating copy to clipboard operation
har-export-trigger copied to clipboard

devtools.netmonitor.har.enableAutoExportToFile Not Working

Open ybahador opened this issue 6 years ago • 6 comments

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.

ybahador avatar Nov 13 '18 21:11 ybahador

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

soulgalore avatar Nov 24 '18 12:11 soulgalore

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?

shonasong avatar Nov 26 '18 15:11 shonasong

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 avatar Nov 29 '18 09:11 vasinkd

@vasinkd Thank you very much!

shonasong avatar Nov 30 '18 00:11 shonasong

@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.

frvwfr2 avatar Dec 14 '18 19:12 frvwfr2

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

vasinkd avatar Jan 04 '19 12:01 vasinkd