Skip to content

Instantly share code, notes, and snippets.

@quentint
Forked from amishshah/har-extract.js
Last active December 12, 2017 11:21
Show Gist options
  • Save quentint/7236a6a7cae187507b0c1dfd4b1ed1c5 to your computer and use it in GitHub Desktop.
Save quentint/7236a6a7cae187507b0c1dfd4b1ed1c5 to your computer and use it in GitHub Desktop.
Rough script to extract files from HTTP Archive (HAR) files
const fs = require('fs');
const file = JSON.parse(fs.readFileSync('./my-file.har')).log;
const targetMimeType = 'application/font-woff';
let count = 0;
for (const entry of file.entries) {
if (entry.response.content.mimeType === targetMimeType) {
let fileName = entry.request.url.split('/').pop();
// Ensure output directory exists before running!
fs.writeFileSync(`./output/${fileName}`, new Buffer(entry.response.content.text, 'base64'), 'binary');
count++;
}
}
console.log(`Grabbed ${count} files`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment