From 5ff6680cee720499aa520436dd36cd4341d0a372 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sat, 3 Aug 2024 16:41:36 +0900 Subject: [PATCH] Update har.js --- lib/har.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/har.js b/lib/har.js index 57cfec6..2b4e846 100644 --- a/lib/har.js +++ b/lib/har.js @@ -5,7 +5,7 @@ var FILE = require("lib/file"); var HARObject = function() { this.filename = null; - this.data = null; + this.data = {}; this.entryIndex = 0; this.onEntry = null; @@ -19,23 +19,28 @@ var HARObject = function() { this.load = function(filename) { this.filename = filename; - this.data = JSON.parse(FILE.readFile(filename, PipeIPC.CdoUTF_8)); + this.data = JSON.parse(FILE.readFile(this.filename, PipeIPC.CdoUTF_8)); + return this; }; - this.play = function(onEntry) { - if (this.data = null) - return; - - var entries = this.data.entries; + this.play = function() { + var entries = this.data.log.entries; while (this.entryIndex < entries.length) { - var entry = this.data.entries[entryIndex]; + var entry = entries[this.entryIndex]; if (typeof this.onEntry !== "function") { - console.log(entry.request.httpVersion, entry.request.method, entry.response.status, entry.request.url); + console.log( + '[' + entry.startedDateTime + ']', + '"' + [entry.request.method, entry.request.url, entry.request.httpVersion].join(' ') + '"', + entry.request.url, + entry.request.httpVersion, + entry.response.status, + entry.response.content.size + ); } else { try { - this.onEntry(this, entry, entry.request, entry.response); + this.onEntry(this, entry, entry.request, entry.response, this.entryIndex); } catch (e) { console.error(e.message); } @@ -43,16 +48,20 @@ var HARObject = function() { this.entryIndex++; } + + return this; }; this.rewind = function() { this.entryIndex = 0; + + return this; }; }; exports.HARObject = HARObject; -exports.VERSIONINFO = "HAR manipulate and replay tools version 0.1.1"; +exports.VERSIONINFO = "HAR manipulate and replay tools version 0.1.2"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = require;