Last active
May 4, 2020 23:47
-
-
Save walkness/a3bd5125cbe8ea4376b799ca07c70f95 to your computer and use it in GitHub Desktop.
Provides a simple way to extract a list of unique domains from a HAR file (e.g. as downloadable from Chrome dev tools)
This file contains 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
const fs = require('fs') | |
const urlLib = require('url') | |
function domainsFromHar(filePath) { | |
const rawData = fs.readFileSync(filePath) | |
const json = rawData && JSON.parse(rawData) | |
const { log } = json || {} | |
if (!log) return | |
const { pages, entries } = log | |
const urls = pages | |
.map(page => page.title) | |
.concat(entries.map(entry => entry.request.url)) | |
const domains = urls.map(url => urlLib.parse(url).host) | |
const uniqueDomains = [...new Set(domains)] | |
return JSON.stringify(uniqueDomains, null, 2) | |
} | |
const filePathArg = process.argv[2] | |
console.log(domainsFromHar(filePathArg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment