Skip to content

A CLI utility to record and insert pages into a HAR file

Notifications You must be signed in to change notification settings

tom-miseur/har-pager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

har-pager

har-pager is a CLI utility that allows HAR pages to be recorded in such a way that they can subsequently be merged into a HAR file, captured elsewhere at the same time as the recording, that does not contain them.

What is a HAR page?

The HAR spec caters for associating requests to a parent page object. Although optional, it can be useful as a means of grouping requests that share something in common. The original intent behind a HAR page was likely for it to represent a browser navigation, it can also be used to denote the "user action" that the requests belong to. For example, a "Submit Login" page could contain all the requests that took place when the user submitted a login form.

Use case with k6

k6 uses HAR page information to generate groups when converting HAR recordings to k6 scripts using the Import HAR functionality in Grafana Cloud k6. The main benefit of this is to make the resulting auto-generated HTTP code easier to interpret, particularly when dealing with lengthy flows with many requests.

Installation

Make sure you have Go installed on your machine. If not, you can download it from here.

From source:

  1. Clone the repository
  2. Run go build in the root directory
  3. Move the resulting har-pager binary to a location in your PATH environment variable (so that it can be run from anywhere)

Pre-built binaries:

Can be found in Releases

Usage

har-pager has two modes of operation: record and merge.

Record mode

har-pager record MyPages

In record mode, you enter the names of the pages you want to generate. Running the above command will start the recording process:

Recording started. To finish the recording, press CTRL/CMD+C
v Page name: 

Now would be a good time to also start the HAR recording. This could be done through Chrome DevTools' Network tab, a web proxy like Telerik's Fiddler or mitmproxy, or even the k6 Browser Recorder.

Enter a page name, hit return, and then perform the action that results in HTTP requests. For example:

v Page name: Navigate to Homepage
Starting page 'Navigate to Homepage'. Enter next page, or CTRL/CMD+C to stop recording.

Continue this loop as necessary, using CTRL/CMD+C to stop the recording and save the page log.

Merge mode

har-pager merge MyPages MyRecording.har MyRecording-merged.har

In merge mode, a recorded page log can be merged with the corresponding HAR file (2nd parameter). The 3rd parameter is the output HAR file.

The merging process is quite simple: the generated page log contains a timestamp for each page that corresponds to when it was entered during the recording. This timestamp is then compared with request startDateTime timestamps in the HAR file to determine whether a request took place between this timestamp and that of the subsequent page. Should that be the case, a pageRef field is added to the request object, linking it to the page.

About

A CLI utility to record and insert pages into a HAR file

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages