Skip to content

Instantly share code, notes, and snippets.

@walkness
Last active May 4, 2020 23:47
Show Gist options
  • Save walkness/a3bd5125cbe8ea4376b799ca07c70f95 to your computer and use it in GitHub Desktop.
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)
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