Skip to content

Instantly share code, notes, and snippets.

@juananpe
Created Mar 28, 2020
Embed
What would you like to do?
parsing a HAR file
const fs = require("fs");
const contents = fs.readFileSync("/tmp/discordapp.com.har");
const jsonContent = JSON.parse(contents);
let mensajes = {};
jsonContent.log.entries.forEach(entry => {
if (entry.request.method == "POST") {
if (entry.request.postData && entry.request.postData.text.includes("content")) {
let id = JSON.parse(entry.response.content.text).id;
let text = JSON.parse(entry.request.postData.text).content;
mensajes[id] = text;
}
} else if (entry.request.method == "PATCH" || entry.request.method == "DELETE") {
let id = entry.request.url.split("messages/")[1];
let text = entry.request.postData? JSON.parse(entry.request.postData.text).content : "";
mensajes[id] = text;
}});
console.log(Object.keys(mensajes).map( key => mensajes[key]).join(""));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment