Registry / testing / fetch-har

fetch-har

JSON →
library12.0.4jsnpmunverified

Make a fetch request from a HAR (HTTP Archive) definition. Current stable version is 12.0.4, requiring Node >=22 and ESM. Converts HAR log entries into native fetch() calls, supporting Node 18+ and all browsers with native fetch. Key differentiators: no polyfills needed, works across browsers and Node, supports file uploads from buffers or File objects, and integrates with mocking libraries like nock or MSW. Maintained by readme.io with cross-browser CI testing.

testing
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Default export only; named import will be undefined. ESM-only, no CommonJS.

import fetchHAR from 'fetch-har'

Package is ESM-only since v12 (Node >=22). require() will throw ERR_REQUIRE_ESM.

import fetchHAR from 'fetch-har'

TypeScript types are included. Options type can be imported for customizing requests.

import type { Options } from 'fetch-har'

Demonstrates importing fetch-har, constructing a HAR object with an Authorization header, calling fetchHAR, and parsing the JSON response.

import fetchHAR from 'fetch-har'; const har = { log: { entries: [ { request: { method: 'GET', url: 'https://httpbin.org/get', headers: [ { name: 'Authorization', value: 'Bearer ' + (process.env.API_KEY ?? '') }, ], }, }, ], }, }; const response = await fetchHAR(har); const data = await response.json(); console.log(data);
Debug
Known footguns
breakingNode >=22 required (v12+). Node 18 or 20 will not work.
gotchafiles option is required for file uploads unless the HAR contains data URLs. Missing both causes a fatal exception.
gotchaThe init option's body and credentials may be overridden by the HAR definition.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
3
ahrefsbot
1
Resources