Aggregation and Analysis of File Requests with HAR

Transfer of Ticimax e-commerce data to Google Analytics 4 (GA4) and Ads via Google Tag Manager (GTM) tags, setup of conversion and remarketing tags

Ceyhun Enki Aksan
Ceyhun Enki Aksan Entrepreneur, Maker

During the web page loading process, numerous files are downloaded in the background, both statically and dynamically, based on different formats. Through the browser’s Network tab, you can access information such as which stage each file was downloaded, its size, and its content. Files can also be grouped according to their formats. However, to examine and/or analyze files offline outside of the browser, files are typically downloaded individually or evaluated via the Network panel. In this article, I will discuss an alternative method—using HAR—to capture requests.

During the page loading process, we can observe requests (GET, POST, etc.) and the responses sent or returned as a result of these requests, all via the Network tab.

Network Signals
Network Signals

When you right-click on a relevant request, either generally or according to a specific format, a Save all as HAR with content option appears. With this option, the relevant requests can be saved in HAR format (.har) to your computer. Below is an example HAR content containing JavaScript requests.

So, what is HAR?

Play

HTTP Archive (HAR) Format

HTTP Archive (HAR) is a file format that results from logging a web browser’s interaction with a website in JSON format. This archive contains detailed performance data related to the requests (headers, metadata, cookies, form data, etc.) and can be exported externally1 2 3.

[mermaid] flowchart TD C[Log] C —>D[Creator] C —>E[Pages] C —>F[Entries] [/mermaid]

This format was developed by the Web Performance Working Group of the World Wide Web Consortium (W3C), but has never been published1.

The following is an example of a HAR archive content containing JavaScript requests.

{
  "log": {
    "version": "1.2",
    "creator": {
      "name": "WebInspector",
      "version": "537.36"
    },
    "pages": [],
    "entries": [
      {
        "_initiator": {
          "type": "script",
          "stack": {
            "callFrames": [
              {
                "functionName": "send",
                "scriptId": "65",
                "url": "https://script.bugpilot.io/d1d055a0-ece1-4f91-9ac1-9ae73f43df0d/adopto.js",
                "lineNumber": 572,
                "columnNumber": 665
              },
              {
                "functionName": "Ta",
                "scriptId": "164",
                "url": "https://www.clarity.ms/s/0.7.7/clarity.js",
                "lineNumber": 1,
                "columnNumber": 40543
              },
              {
                "functionName": "",
                "scriptId": "164",
                "url": "https://www.clarity.ms/s/0.7.7/clarity.js",
                "lineNumber": 1,
                "columnNumber": 39956
              },
              {
                "functionName": "",
                "scriptId": "164",
                "url": "https://www.clarity.ms/s/0.7.7/clarity.js",
                "lineNumber": 1,
                "columnNumber": 7773
              },
              {
                "functionName": "",
                "scriptId": "164",
                "url": "https://www.clarity.ms/s/0.7.7/clarity.js",
                "lineNumber": 1,
                "columnNumber": 7878
              },
              {
                "functionName": "o",
                "scriptId": "164",
                "url": "https://www.clarity.ms/s/0.7.7/clarity.js",
                "lineNumber": 1,
                "columnNumber": 6595
              }
            ]
          }
        }
      }]
    // ...
  }
}

HAR files can also be used to download relevant files4 5, including all interactions that occur during the rendering of a website, and can be processed via various tools6 7 8.

Network Signals
Network Signals

Github. “swiss-army-scripts”. Under the har-js-analyzer/js-file-downloader.py script, it is possible to download files present in a HAR file (for example, this script handles JS-formatted files). Using har-js-analyzer/js-analyzer.py, a basic analysis of the relevant HAR content can be performed.

Basic HAR Analysis Process

The sample code snippet contains requests related to JS files, and the analysis process is also conducted within this context. Naturally, since the file format can be changed, the format option is removed, allowing the relevant operations to be performed for all requests.

import json
from haralyzer import HarParser, HarPage

with open('har_data.har', 'r') as f:
    har_parser = HarParser(json.loads(f.read()))

print har_parser.browser
# {u'name': u'Firefox', u'version': u'25.0.1'}

print har_parser.hostname
# 'humanssuck.net'

for page in har_parser.pages:
    assert isinstance(page, HarPage, None)
    # returns True for each

Using the Python snippet in the har-image-analyzer.py file, you can access information such as the number of entry entries, columns within each entry, summary statistics (min, max, mean, etc.) related to requests, image file names and sizes, group images, and compare total loading times.

  • Number of entries: 38
  • Number of image requests: 18
File NameSize
wikipedia.png13444 B
100px-Salvador_Dal%C3%AD_1939.jpg4674 B
150px-The_Simpsons_yellow_logo.svg.png6716 B
100px-YuanEmperorAlbumKhubilaiPortrait.jpg3038 B
68px-Ask_and_Embla_by_Robert_Engels.jpg4934 B
250px-Sergei_Rachmaninoff_LOC_33969u.jpg18170 B
48px-Notification-icon-Wikiquote.svg.png1322 B
48px-Notification-icon-Wikisource-logo.svg.png1784 B
48px-Notification-icon-Commons-logo.svg.png960 B
48px-Notification-icon-Wiktionary-logo.svg.png4270 B
48px-Notification-icon-Wikidata-logo.svg.png568 B
48px-Notification-icon-Wikibooks-logo.svg.png2770 B
48px-Notification-icon-Wikiversity-logo.svg.png1813 B
48px-MediaWiki-2020-icon.svg.png2890 B
48px-Notification-icon-Wikivoyage-logo.svg.png628 B
48px-Notification-icon-Wikispecies-logo.svg.png1680 B
48px-Notification-icon-Meta-logo.svg.png2010 B
171px-Logo_original-t.png9212 B
File NameRequest CountTotal SizeMaximum Load TimeMinimum Load TimeAverage Load Time
wikipedia.png113444 B318.45 ms318.45 ms318.45 ms
100px-Salvador_Dal%C3%AD_1939.jpg14674 B522.38 ms522.38 ms522.38 ms
150px-The_Simpsons_yellow_logo.svg14977 B285.14 ms285.14 ms285.14 ms
220px-Leonhard_Euler_2.jpg113595 B308.75 ms308.75 ms308.75 ms
1200px-Manhattan_wikivoyage_banner.jpg1142069 B1.25 s1.25 s1.25 s
2000px-BlankMap-World6.svg1171246 B982.39 ms982.39 ms982.39 ms
1400px-Rubik’s_cube.svg.png1182729 B1.22 s1.22 s1.22 s
2000px-Map_of_the_world_by_the_US_Gov_as_of_2016.svg1710413 B1.54 s1.54 s1.54 s

Footnotes

  1. HTTP Archive (HAR) format 2
  2. HAR (file format). Wikipedia
  3. View request payload. Network features reference. Chrome Developer
  4. HAR Viewer
  5. Google Administrator Tool Kit. HAR Analyzer
  6. Github. “swiss-army-scripts”. har-js-analyzer/js-file-downloader.py
  7. Leonardo Faria. “How to Use HAR Files to Analyze Performance Over Time”
  8. Rakesh Seal. “A Comprehensive Guide on HAR Files”