Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

chrome-har

sitespeedio769.3kMIT1.0.1

Create HAR files from Chrome Debugging Protocol data.

chrome, har, webperf

readme

Chrome-har

Unit tests

Create HAR files based on Chrome DevTools Protocol data.

We got tired of waiting for the +30K engineers at Google implementing a way to automate to get a HAR file https://issues.chromium.org/issues/40809195 so we implemented our own solution in the mean time.

Code originally extracted from Browsertime, initial implementation inspired by Chromedriver_har.

Create a new bug report

Make sure to generate a event trace log file that we can use to recreate your issue. If you use Browsertime you can enable the trace with --chrome.collectPerfLog:

$ browsertime --chrome.collectPerfLog -n 1 https://www.sitespeed.io

Then take the file named chromePerflog-1.json.gz and put it in a gist or make it availible to us in any way you want.

If you use sitespeed.io:

$ sitespeed.io --browsertime.chrome.collectPerfLog -n 1 https://www.sitespeed.io

Support for Response Bodies

If you use Chrome-har standalone (without Browsertime/sitespeed.io) you can use get the response bodies in HARs if they are set on the response object by the caller and if the includeTextFromResponseBody option is set to true.

For example:

const harEvents: Array<any> = [];

client.on('Network.requestIntercepted', async (params: any) => {
  // Get the response body
  const response = await client.send(
    'Network.getResponseBodyForInterception',
    { interceptionId: params.interceptionId },
  );

  // Set the body on the response object
  if (params.response != null) {
    params.response.body = response.body;
  } else {
    params.response = response;
  }

  // Continue the request
  await client.send(
    'Network.continueInterceptedRequest',
    { interceptionId: params.interceptionId },
  );

  harEvents.push({ method, params });
});

const har = harFromMessages(harEvents, {includeTextFromResponseBody: true});

changelog

CHANGELOG

1.0.1 - 2024-10-11

Fixed

  • Try/catch broken dates #130.

1.0.0 - 2024-10-08

Breaking

The project was transitioned to a pure ESM package. This follows along with the changed done in sitespeed.io and Browwsertime. This will make the project easier to maintain #129.

Fixed

  • Removed dayjs dependency #128.
  • Removed uuid dependency #127.
  • Updated to tough cookie 5.0.0 #126.

0.13.5 - 2024-07-12

Fixed

  • Always take care of Network.responseReceivedExtraInfo even if its fired early, thank you ifduyue for PR #120.

(0.13.4 was never released)

0.13.3 - 2024-07-05

Fixed

0.13.2 - 2023-07-30

Fixed

0.13.1 - 2023-02-22

Fixed

  • Updated dependencies to latest versions #105.
  • Remove adding headers from extra parameters. Using the CDP Fetch API manipulating responses, the extra response info holds the old un-manipulated headers, so when copying the ones that do not exist, this breaks. Fixed in #100.

0.13.0 - 2022-02-04

Added

  • Add _isLinkPreload on the request object if it is isLinkPreload #94.

0.12.0 - 2020-10-29

Added

  • Addend encoding field to type response, thank you Miroslav Balaz for the PR #79.
  • Include chunk information in the response see #88.
  • Add custom field _resourceType thank you Peng-Yu Chen for PR #83

    Fixed

  • Use Page.frameRequestedNavigation see #90.
  • Capture redirect before page for traces generated by Lighthouse, thank you Michael Dijkstra for PR #89.

0.11.12 2020-09-09

Fixed

  • Removed test directory from the release, thank you Yury Michurin for the PR #75.

0.11.11 2020-08-06

Fixed

0.11.10 2020-07-29

Added

  • Parse extra info events (parse extra request data from the Network.requestWillBeSentExtraInfo event and parse extra response data from the Network.responseReceivedExtraInfo event), thank you Michael Dijkstra for the PR #71.

  • Update to day-js 1.8.31.

0.11.9 2020-05-26

Fixed

  • Updated dependencies: dayjs - 1.8.27, debug: 4.1.1, tough-cookie - 4.0.0, uuid - 8.0.0

0.11.8 (never released)


Added

  • Include iframe request when frame is not attached #68 - thank you Michael Dijkstra for the PR!

  • Include response canceled by Chrome or user action #67 - thank you Michael Dijkstra for the PR!

0.11.7 2020-03-09

Fixed

  • And excluded the shrinkwrap file again.

0.11.6 2020-03-09

Fixed

  • Exclude the test folder from the release.

0.11.5 2020-03-09

Fixed

  • Added a shrinkwrap file.

0.11.4 2019-10-16

Fixed

  • Reverted the _initiator field fix since that was an old upstream issue in Chrome #44.

0.11.3 2019-10-14

Fixed

  • Better parsing of the _initiator field fixing an error for some HARs, thank you Aleksandr Semyonov for the PR #44.

0.11.2 2019-09-21

Fixed

  • Extra check that we really got a response in the trace #54

0.11.1 2019-09-14

Fixed

  • Catch if a request misses the response/timings #53.

0.11.0 2019-07-23

Added

  • Include Chrome request id as _requestId to make it simpler in Browsertime to add response bodies #50.

0.10.0 2019-01-09

Added

0.9.1 2019-01-03

Fixed

  • And also use the URL fragment so we can keep that #40.

0.9.0 2019-01-03

Added

  • Keep hash (#) in URLs. We used to remove them to follow the same path as Chrome but Firefox do not and it breaks later in our tool chain to change the URL #39.

0.8.1 2019-01-03

Fixed

  • Tech: Simplify logic for skipping pages.

0.8.0 2019-01-01

Added

  • Skip support for multi page navigation by script (this makes things much easier in Browsertime) #38.

0.7.1 2018-12-13

Fixed

  • Pickup requests/responses that happens before navigation and block some sctript navigations #36.

0.7.0 2018-11-23

Added

  • Catch requestWillBeSent that happens before navigation #34. This fixes when you click on a link in Chrome that generates a new navigation.

0.6.0 2018-11-23

Added

  • Use dayjs instead of moment #33.
  • Support for having a HAR with multiple pages from Browsertime #30.
  • Internal: Split the code to different files to make it easier to read the code #32.

0.5.0 2018-10-12

Added

  • Catch Chrome navigating within page #28.

0.4.1 2018-06-01

Fixed

0.4.0 2018-05-29

Added

  • Including cached entries in the HAR now generates a HAR that validates against the HAR schema.
  • Include responses that were pushed with HTTP2. Thanks to Martino Trevisan! #21

0.3.2 2018-04-07

Fixed

  • Fixes for situations that could result in incorrect HARs (missing startedDateTime or missing first entry).
  • Format IPv6 addresses so HARs validate with har-validator

0.3.1 2018-03-29

Fixed

  • Also act on Page.frameScheduledNavigation (needed for Chrome 66 and coming Browsertime 3.0)

0.3.0 2018-03-15

Added

  • Add more information about request initiator to HAR. Thanks to David Dadon! #9

0.2.3 2017-10-15

Fixed

  • Prevent creating HAR files with empty pages (i.e. pages with no entries).

0.2.2 2017-06-30

Fixed

  • Be extra careful when parsing JSON see #4

0.2.1 2017-05-31

Fixed

  • Remove unused files from npm distribution.

0.2.0 2017-05-31

Added

  • Add "serverIPAddress" field to entries.
  • Set bodySize for requests correctly.
  • Set bodySize and compression for responses correctly.
  • Add _transferSize field for responses, just like Chrome does.

0.1.0 2017-03-05

Added

  • Initial release