Registry / http-networking / header-generator

header-generator

JSON →
library2.1.82jsnpmunverified

header-generator is a core component of the Apify Fingerprint Suite, a toolkit designed to generate realistic, browser-like HTTP headers for web scraping and anti-fingerprinting purposes. Currently at version 2.1.82, the package receives frequent, automated updates primarily for its underlying data models, ensuring the generated headers remain current and effective against sophisticated bot detection. While its standalone GitHub repository is marked as deprecated, the package itself is actively maintained and developed as an integral part of the larger fingerprint-suite project. It allows developers to programmatically create HTTP headers that mimic various browsers, operating systems, devices, and locales, helping scrapers blend in more effectively with legitimate user traffic. Its key differentiator is the focus on realism and configurability based on real-world browser data.

npm install header-generator
INSTALL
IMPORT
SIG · HEADER-GENERATOR
H
header-generator
http-networkingjavascriptv2.1.82
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

HeaderGenerator
import { HeaderGenerator } from 'header-generator';
const { HeaderGenerator } = require('header-generator');
While CommonJS `require` works in Node.js, modern TypeScript/ESM projects should use named imports. This is the primary class for generating headers.
PRESETS
import { PRESETS } from 'header-generator';
import PRESETS from 'header-generator';
PRESETS is a named export object containing predefined configurations for common browser/OS combinations.
HeaderGeneratorOptions
import type { HeaderGeneratorOptions } from 'header-generator';
import { HeaderGeneratorOptions } from 'header-generator';
This is a TypeScript type definition for the options object passed to the HeaderGenerator constructor or getHeaders method. It should be imported as a type.

Demonstrates initializing HeaderGenerator with options, generating headers with global and specific constraints, and using predefined PRESETS.

import { HeaderGenerator, PRESETS } from 'header-generator'; (async () => { // Initialize the generator with default constraints const headerGenerator = new HeaderGenerator({ browsers: [ { name: 'chrome', minVersion: 90 }, { name: 'firefox', minVersion: 80 }, 'safari' ], devices: ['desktop', 'mobile'], operatingSystems: ['windows', 'macos', 'linux', 'android', 'ios'], locales: ['en-US', 'en', 'de-DE'], httpVersion: '2' }); // Generate headers based on the global options (randomly selected from possibilities) const headers1 = headerGenerator.getHeaders(); console.log('Generated Headers (default options):', headers1); // Generate headers with specific, overriding options for a single call const headers2 = headerGenerator.getHeaders({ operatingSystems: ['linux'], devices: ['desktop'], locales: ['es-ES'] }); console.log('Generated Headers (Linux desktop, Spanish locale):', headers2); // Initialize with a preset for a common configuration const modernWindowsChromeGenerator = new HeaderGenerator(PRESETS.MODERN_WINDOWS_CHROME); const headers3 = modernWindowsChromeChromeGenerator.getHeaders(); console.log('Generated Headers (Modern Windows Chrome preset):', headers3); // Headers are generated randomly, subsequent calls yield different results const headers4 = headerGenerator.getHeaders(); console.log('Another set of Headers (randomized):', headers4); })();
Debug
Known issues
gotchaThe standalone 'apify/header-generator' GitHub repository is marked as deprecated. While the `header-generator` npm package remains active and receives updates (primarily for its underlying data models), it is now managed as part of the broader Apify `fingerprint-suite` project. Users are encouraged to refer to the `fingerprint-suite` documentation for the latest context and best practices.
fix
Always consult the main `fingerprint-suite` repository for overarching architecture and updated guidelines regarding `header-generator`'s usage.
affects: >=2.0.0
gotchaThe `getHeaders()` method always generates a *random* set of headers from the possible options. Calling it multiple times with the same parameters will likely produce different header sets, which is by design for anti-fingerprinting, but might be unexpected if deterministic output is desired.
fix
Store the result of `getHeaders()` if you need to reuse the same set of headers. Do not assume repeated calls will yield identical results without explicit caching.
affects: >=1.0.0
gotchaThe generated headers do not include request-dependent headers such as `Host`, `Content-Length`, `Cookie`, or `If-None-Match`. These headers are specific to the individual HTTP request and must be added by the user's HTTP client or application logic.
fix
Manually add request-specific headers to the generated object before sending an HTTP request. For example, `const fullHeaders = { ...generatedHeaders, Host: 'example.com', 'Content-Length': body.length };`
affects: >=1.0.0
gotchaThe `httpVersion` option in `HeaderGeneratorOptions` significantly impacts the structure and content of the generated headers, as HTTP/1 and HTTP/2 requests use different header sets (e.g., HTTP/2 uses `:method`, `:authority`, `:scheme`, `:path` pseudo-headers).
fix
Ensure the `httpVersion` option matches the actual HTTP version used by your client to avoid sending malformed or incorrect headers.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'header-generator'
Incorrect import path, missing `header-generator` from `package.json`, or trying to use CommonJS `require` in an ESM-only context without proper configuration.
fix
Ensure `header-generator` is listed in `dependencies` and installed (`npm install header-generator`). Use `import { HeaderGenerator } from 'header-generator';` for ESM/TypeScript projects. For older Node.js or CommonJS, `const { HeaderGenerator } = require('header-generator');`.
TypeError: headerGenerator.getHeaders is not a function
The `headerGenerator` variable was not correctly initialized as an instance of `HeaderGenerator` or was reassigned.
fix
Verify that `headerGenerator = new HeaderGenerator(...)` was called successfully before attempting to use `getHeaders()`.
Property 'someUnknownOption' does not exist on type 'HeaderGeneratorOptions'
Attempting to pass an unrecognized option to the HeaderGenerator constructor or `getHeaders` method when using TypeScript, indicating a type mismatch or invalid configuration.
fix
Consult the `HeaderGeneratorOptions` interface and documentation to ensure all options passed are valid. Remove or correct any misspelled or unsupported options.
Upgrade
Version history
2.1.82latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
header-generator — npm install header-generator · libregistry