Skip to content

Instantly share code, notes, and snippets.

@nokazn
Created August 5, 2021 04:05
Show Gist options
  • Select an option

  • Save nokazn/5bd01c9715d839f3184088b15642f6a3 to your computer and use it in GitHub Desktop.

Select an option

Save nokazn/5bd01c9715d839f3184088b15642f6a3 to your computer and use it in GitHub Desktop.
.har ファイルから URL を取り出して出力する
import * as fs from 'fs';
import { z } from 'zod';
const SCHEMA = z.object({
log: z.object({
entries: z.array(
z.object({
request: z.object({
url: z.string(),
}),
}),
),
}),
});
const main = () => {
const harFilePath = process.argv[2];
if (typeof harFilePath !== 'string') {
throw new Error('.har ファイルのパスを指定してください。');
}
const file = fs.readFileSync(harFilePath).toString();
const json = JSON.parse(file);
const res = SCHEMA.parse(json);
const urls = res.log.entries.map((e) => e.request.url).join('\n');
process.stdout.write(urls);
};
main();
{
"devDependencies": {
"@types/node": "^16.4.12",
"ts-node": "^10.1.0",
"typescript": "^4.3.5"
},
"dependencies": {
"zod": "^3.7.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment