Last active
April 2, 2020 16:49
-
-
Save RichAyotte/6551eac1de15b128de8144aa5094e22a to your computer and use it in GitHub Desktop.
Parse HAR
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
/* | |
* @Author: Richard Ayotte | |
*/ | |
const fs = require('fs') | |
const url = require('url') | |
const [, , harFile] = process.argv | |
const getJsonRpcUrls = entry => | |
RegExp('https://api.infura.io/v1/jsonrpc').test(entry.request.url) | |
const harData = fs.readFileSync(harFile) | |
const har = JSON.parse(harData) | |
const report = har.log.entries.filter(getJsonRpcUrls).map(({ request }) => { | |
if (request.method === 'GET') { | |
const parsedUrl = url.parse(request.url) | |
const rpc = parsedUrl.pathname.split('/').pop() | |
return { | |
method: request.method, | |
rpc, | |
params: request.queryString, | |
} | |
} | |
if (request.method === 'POST') { | |
const postData = JSON.parse(request.postData.text) | |
return { | |
method: request.method, | |
rpc: postData.method, | |
params: postData.params, | |
} | |
} | |
}) | |
const uniqueRpcs = [...new Set(report.map(entry => entry.rpc))].sort() | |
console.log(uniqueRpcs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment