HTTP Header Generator

2.1.82 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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);
})();

view raw JSON →