Skip to content

Instantly share code, notes, and snippets.

@Vanuan
Last active March 16, 2019 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vanuan/9d496f9d53183dcefffdeb2511e4f86a to your computer and use it in GitHub Desktop.
Save Vanuan/9d496f9d53183dcefffdeb2511e4f86a to your computer and use it in GitHub Desktop.
Save images from browser
  1. Save as HAR with content
  2. Rename file to har.json
  3. Download node script
  4. Modify filter expression
  5. Run node script.
var json = require('./har');
var fs = require('fs');
function write(filename, base64content) {
var fd, content;
try {
fd = fs.openSync(filename, 'w');
content = Buffer.from(base64content, 'base64');
fs.writeFileSync(fd, content);
console.log('written', filename)
} catch (err) {
console.log(err)
/* Handle the error */
} finally {
if (fd !== undefined)
fs.closeSync(fd);
}
}
var entries = json.log.entries;
entries.forEach(entry => {
var file = entry['response']['content'];
var fileUrl = entry.request.url;
if(file.mimeType=='image/jpeg') {
var text = file.text;
// modify match expression
var match = fileUrl.match(/https:\/\/.*\/(.*\.jpg).*/)
if(match) {
var fileName = match[1];
write('./' + fileName, text);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment