Skip to content

Instantly share code, notes, and snippets.

@juananpe
Created March 28, 2020 16:20
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 juananpe/b9730a04bc76ad54604f9a7ac657cc36 to your computer and use it in GitHub Desktop.
Save juananpe/b9730a04bc76ad54604f9a7ac657cc36 to your computer and use it in GitHub Desktop.
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