# har-replay

> Utility to replay a HAR file

Latest version **0.2.2** (published 2025-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install har-replay
pnpm add har-replay
yarn add har-replay
bun add har-replay
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2025-03-11 |
| First published | 2017-02-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Avi Stramer |
| Maintainers | avistramer |
| Keywords | HAR |

## Links

- npm: https://www.npmjs.com/package/har-replay
- Repository: https://github.com/testable/har-replay
- Issues: https://github.com/testable/har-replay/issues
- npm.io page: https://npm.io/package/har-replay

## Dependencies (4)

- [axios](https://npm.io/package/axios.md) ^1.8.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [moment](https://npm.io/package/moment.md) ^2.30.1
- [form-data](https://npm.io/package/form-data.md) ^4.0.0

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2025-03-11
- 0.2.1 — 2023-05-31
- 0.2.0 — 2023-04-21
- 0.0.12 — 2019-08-28
- 0.0.10 — 2017-12-07
- 0.0.8 — 2017-12-07
- 0.0.7 — 2017-04-15
- 0.0.6 — 2017-04-15
- 0.0.5 — 2017-02-20
- 0.0.4 — 2017-02-13
- 0.0.3 — 2017-02-10
- 0.0.2 — 2017-02-08
- 0.0.1 — 2017-02-08

## README

# HAR Replay Utility

A simple utility to replay the contents of a [HTTP Archive (HAR) file](https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HAR/Overview.html) while maintaining the delay between requests. Utilizes the [request npm module](https://www.npmjs.com/package/request) to execute the HTTP replay requests.

## Installation

Available on the public NPM registry as `har-replay`.

```
npm install har-replay --save
```

## Example

```javascript
var harReplay = require('har-replay');
harReplay.load('example.har');
```

## API

`harReplay.load(file, [options])`

Load and replay the request in the HAR file found at local path `file`. A delay of `entry.startDateTime - firstEntry.startDateTime` will be applied to all requests after the first one.

**options**

* `timeout`: A timeout (milliseconds) to wait for a reply. Defaults to 1 minute.
* `beforeRequest`: A `function(request) { ... }` to manipulate the request before it is replayed. If this method returns `false` then the request will not be replayed. If your function returns a promise, the library will `await` it before continuing on to make the request.
* `onResponse`: A `function(response, request) { ... }` to process the response that results from a replayed request. See  for the axios response schema.
* `onFinish`: A callback function that gets called once all requests have been replayed and all responses (or errors) have been received.
* `onError`: A `function(error, request) { ... }` callback when any error occurs during replay.
* `replayCachedEntries`: Whether or not to replay requests where the response was loaded from the browser cache. By default this is `false`.

Full Example:

```javscript
const harReplay = require('har-replay');
harReplay.load('example.har', { 
	beforeRequest: function(request) {
		request.headers['Some-New-Header'] = 'abc';
	},
	onResponse: function(response, request, body) {
		console.log(`Response status code for ${request.url}: ${response.status}`);
	},
	onFinish: function() {
		console.log('All done!');
	},
	onError: function(error, request) {
		console.error(error);
	}
});
```

---
_Source: https://npm.io/package/har-replay · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
