{"id":18710675,"url":"https://github.com/apify/header-generator","last_synced_at":"2025-11-03T16:30:52.037Z","repository":{"id":37958652,"uuid":"338265741","full_name":"apify/header-generator","owner":"apify","description":"NodeJs package for generating browser-like headers.","archived":false,"fork":false,"pushed_at":"2022-08-13T20:58:11.000Z","size":1977,"stargazers_count":69,"open_issues_count":0,"forks_count":11,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-11T22:11:26.514Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-12T08:50:12.000Z","updated_at":"2025-03-18T11:29:36.000Z","dependencies_parsed_at":"2022-07-10T00:32:29.258Z","dependency_job_id":null,"html_url":"https://github.com/apify/header-generator","commit_stats":null,"previous_names":["apify/headers-generator"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fheader-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fheader-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fheader-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fheader-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apify","download_url":"https://codeload.github.com/apify/header-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248560097,"owners_count":21124594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T12:35:15.246Z","updated_at":"2025-11-03T16:30:51.996Z","avatar_url":"https://github.com/apify.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# (DEPRECATED) Header generator\n\n---\n\n**DEPRECATED** The `header-generator` package now lives in the [fingerprint-suite](https://github.com/apify/fingerprint-suite) repository. This repository is no longer actively maintained.\n\n---\n\nNodeJs package for generating browser-like headers.\n\n\u003c!-- toc --\u003e\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Presets](#presets)\n- [Result example](#result-example)\n- [API Reference](#api-reference)\n\n\u003c!-- tocstop --\u003e\n\n## Installation\nRun the `npm install header-generator` command. No further setup is needed afterwards.\n## Usage\nTo use the generator, you need to create an instance of the `HeaderGenerator` class which is exported from this package. Constructor of this class accepts a `HeaderGeneratorOptions` object, which can be used to globally specify what kind of headers you are looking for: \n```js\nconst { HeaderGenerator } = require('header-generator');\nlet headerGenerator = new HeaderGenerator({\n        browsers: [\n            {name: \"firefox\", minVersion: 80},\n            {name: \"chrome\", minVersion: 87},\n            \"safari\"\n        ],\n        devices: [\n            \"desktop\"\n        ],\n        operatingSystems: [\n            \"windows\"\n        ]\n});\n```\nYou can then get the headers using the `getHeaders` method, either with no argument, or with another `HeaderGeneratorOptions` object, this time specifying the options only for this call (overwriting the global options when in conflict) and using the global options specified beforehands for the unspecified options:\n```js\nlet headers = headersGenerator.getHeaders({\n        operatingSystems: [\n            \"linux\"\n        ],\n        locales: [\"en-US\", \"en\"]\n});\n```\nThis method always generates a random realistic set of headers, excluding the request dependant headers, which need to be filled in afterwards. Since the generation is randomized, multiple calls to this method with the same parameters can generate multiple different outputs.\n\n## Presets\nPresets are setting templates for common use cases. It saves time writing the same configuration over and over.\n```js\nconst { HeaderGenerator, PRESETS } = require('header-generator');\nlet headerGenerator = new HeaderGenerator(PRESETS.MODERN_WINDOWS_CHROME);\n```\n\nThis preset will fill the configuration for the latest five versions of chrome for windows desktops. Checkout the available presets list [here](https://github.com/apify/header-generator/blob/master/src/presets.ts).\n## Result example\nA result that can be generated for the usage example above:\n```json\n{\n  \"sec-ch-ua-mobile\": \"?0\",\n  \"user-agent\": \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36\",\n  \"accept-encoding\": \"gzip, deflate, br\",\n  \"accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\",\n  \"upgrade-insecure-requests\": \"1\",\n  \"accept-language\": \"en-US,en;0.9\",\n  \"sec-fetch-site\": \"same-site\",\n  \"sec-fetch-mode\": \"navigate\",\n  \"sec-fetch-user\": \"?1\",\n  \"sec-fetch-dest\": \"document\"\n}\n```\n## API Reference\nAll public classes, methods and their parameters can be inspected in this API reference.\n\n\u003ca name=\"HeaderGenerator\"\u003e\u003c/a\u003e\n\n### HeaderGenerator\nHeaderGenerator randomly generates realistic browser headers based on specified options.\n\n\n* [HeaderGenerator](#HeaderGenerator)\n    * [`new HeaderGenerator(options)`](#new_HeaderGenerator_new)\n    * [`.getHeaders(options, requestDependentHeaders)`](#HeaderGenerator+getHeaders)\n    * [`.orderHeaders(headers, order)`](#HeaderGenerator+orderHeaders)\n\n\n* * *\n\n\u003ca name=\"new_HeaderGenerator_new\"\u003e\u003c/a\u003e\n\n#### `new HeaderGenerator(options)`\n\n| Param | Type | Description |\n| --- | --- | --- |\n| options | [\u003ccode\u003eHeaderGeneratorOptions\u003c/code\u003e](#HeaderGeneratorOptions) | default header generation options used unless overridden |\n\n\n* * *\n\n\u003ca name=\"HeaderGenerator+getHeaders\"\u003e\u003c/a\u003e\n\n#### `headerGenerator.getHeaders(options, requestDependentHeaders)`\nGenerates a single set of ordered headers using a combination of the default options specified in the constructor\nand their possible overrides provided here.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| options | [\u003ccode\u003eHeaderGeneratorOptions\u003c/code\u003e](#HeaderGeneratorOptions) | specifies options that should be overridden for this one call |\n| requestDependentHeaders | \u003ccode\u003eObject\u003c/code\u003e | specifies known values of headers dependent on the particular request |\n\n\n* * *\n\n\u003ca name=\"HeaderGenerator+orderHeaders\"\u003e\u003c/a\u003e\n\n#### `headerGenerator.orderHeaders(headers, order)`\nReturns a new object that contains ordered headers.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| headers | \u003ccode\u003eobject\u003c/code\u003e | specifies known values of headers dependent on the particular request |\n| order | \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | an array of ordered header names, optional (will be deducted from `user-agent`) |\n\n\n* * *\n\n\u003ca name=\"BrowserSpecification\"\u003e\u003c/a\u003e\n\n### `BrowserSpecification`\n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | \u003ccode\u003estring\u003c/code\u003e | One of `chrome`, `firefox` and `safari`. |\n| minVersion | \u003ccode\u003enumber\u003c/code\u003e | Minimal version of browser used. |\n| maxVersion | \u003ccode\u003enumber\u003c/code\u003e | Maximal version of browser used. |\n| httpVersion | \u003ccode\u003estring\u003c/code\u003e | Http version to be used to generate headers (the headers differ depending on the version).  Either 1 or 2. If none specified the httpVersion specified in `HeaderGeneratorOptions` is used. |\n\n\n* * *\n\n\u003ca name=\"HeaderGeneratorOptions\"\u003e\u003c/a\u003e\n\n### `HeaderGeneratorOptions`\n\n| Param | Type | Description |\n| --- | --- | --- |\n| browsers | \u003ccode\u003eArray.\u0026lt;(BrowserSpecification\\|string)\u0026gt;\u003c/code\u003e | List of BrowserSpecifications to generate the headers for,  or one of `chrome`, `firefox` and `safari`. |\n| browserListQuery | \u003ccode\u003estring\u003c/code\u003e | Browser generation query based on the real world data.  For more info see the [query docs](https://github.com/browserslist/browserslist#full-list).  If `browserListQuery` is passed the `browsers` array is ignored. |\n| operatingSystems | \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | List of operating systems to generate the headers for.  The options are `windows`, `macos`, `linux`, `android` and `ios`. |\n| devices | \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | List of devices to generate the headers for. Options are `desktop` and `mobile`. |\n| locales | \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | List of at most 10 languages to include in the  [Accept-Language](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language) request header  in the language format accepted by that header, for example `en`, `en-US` or `de`. |\n| httpVersion | \u003ccode\u003estring\u003c/code\u003e | Http version to be used to generate headers (the headers differ depending on the version).  Can be either 1 or 2. Default value is 2. |\n\n\n* * *\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapify%2Fheader-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapify%2Fheader-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapify%2Fheader-generator/lists"}