Skip to content

devtools.netmonitor.har.enableAutoExportToFile Not Working #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ybahador opened this issue Nov 13, 2018 · 6 comments
Open

devtools.netmonitor.har.enableAutoExportToFile Not Working #30

ybahador opened this issue Nov 13, 2018 · 6 comments

Comments

@ybahador
Copy link

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.

@soulgalore
Copy link
Contributor

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

@shonasong
Copy link

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?

@vasinkd
Copy link

vasinkd commented Nov 29, 2018

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

@shonasong
Copy link

@vasinkd Thank you very much!

@frvwfr2
Copy link

frvwfr2 commented Dec 14, 2018

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

@vasinkd
Copy link

vasinkd commented Jan 4, 2019

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: #31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants