Created
May 4, 2018 05:22
-
-
Save jwalanta/7d2055cd855d1526e41ebaab3a6a9567 to your computer and use it in GitHub Desktop.
Convert HAR JSON to Call Tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>HAR to Call Tree</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/themes/default/style.min.css" /> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/jstree.min.js"></script> | |
<style> | |
body{ | |
font-family: monospace; | |
font-size: 0.8em | |
} | |
</style> | |
<script> | |
var callGraph = [] | |
function findReferer(headers){ | |
for (var k in headers){ | |
if (headers[k].name == "Referer"){ | |
return headers[k].value; | |
} | |
} | |
return null; | |
} | |
function addChild(tree, parent, url){ | |
// if parent is null, add to root | |
if ( parent == null ){ | |
tree.push({"text": url}) | |
return; | |
} | |
// start searching for parent | |
for (var k in tree){ | |
if (tree[k]["text"] == parent){ | |
// parent found, add as children | |
if (tree[k]["children"] == undefined) tree[k]["children"] = [] | |
tree[k]["children"].push({"text":url}) | |
return | |
} | |
// if node has children, go deep | |
if (tree[k]["children"] !== undefined){ | |
addChild(tree[k]["children"], parent, url) | |
} | |
} | |
} | |
function har2callgraph(){ | |
var d = JSON.parse($('#harjson').val()); | |
$('#harinput').hide(); | |
var entries = d.log.entries; | |
for (var k in entries){ | |
var url = entries[k].request.url | |
var referer = findReferer(entries[k].request.headers) | |
addChild(callGraph, referer, url) | |
} | |
$("#container") | |
.jstree({'core': {'data': callGraph}}) | |
.on('loaded.jstree', function() { | |
$("#container").jstree('open_all'); | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<h2>HAR to Call Tree</h2> | |
<div id="harinput"> | |
<p>Paste HAR json below:</p> | |
<textarea id="harjson" cols="80" rows="40"></textarea> | |
<br /> | |
<input type="button" value="Show Call Tree" onclick="har2callgraph();"/> | |
</div> | |
<div id="container"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment