fingerprint-generator 2.1.12 → 2.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,26 +1,26 @@
1
1
  {
2
2
  "name": "fingerprint-generator",
3
- "version": "2.1.12",
3
+ "version": "2.1.13",
4
4
  "description": "NodeJS package for generating realistic browser fingerprints.",
5
5
  "homepage": "https://github.com/apify/fingerprint-suite",
6
6
  "engines": {
7
7
  "node": ">=16.0.0"
8
8
  },
9
- "main": "dist/index.js",
10
- "module": "dist/index.mjs",
11
- "types": "dist/index.d.ts",
9
+ "main": "index.js",
10
+ "module": "index.mjs",
11
+ "types": "index.d.ts",
12
12
  "exports": {
13
13
  ".": {
14
- "import": "./dist/index.mjs",
15
- "require": "./dist/index.js",
16
- "types": "./dist/index.d.ts"
14
+ "import": "./index.mjs",
15
+ "require": "./index.js",
16
+ "types": "./index.d.ts"
17
17
  }
18
18
  },
19
19
  "scripts": {
20
20
  "build": "npm run clean && npm run compile",
21
- "postbuild": "cp -r src/data_files dist/ && cp ../../README.md dist/",
21
+ "postbuild": "cp -r src/data_files && cp ../../README.md ",
22
22
  "clean": "rimraf ./dist",
23
- "compile": "tsc -p tsconfig.build.json && gen-esm-wrapper ./dist/index.js ./dist/index.mjs",
23
+ "compile": "tsc -p tsconfig.build.json && gen-esm-wrapper ./index.js ./index.mjs",
24
24
  "copy": "ts-node -T ../../scripts/copy.ts"
25
25
  },
26
26
  "repository": {
@@ -33,8 +33,8 @@
33
33
  "url": "https://github.com/apify/fingerprint-suite/issues"
34
34
  },
35
35
  "dependencies": {
36
- "generative-bayesian-network": "^2.1.10",
37
- "header-generator": "^2.1.12",
36
+ "generative-bayesian-network": "^2.1.13",
37
+ "header-generator": "^2.1.13",
38
38
  "tslib": "^2.4.0"
39
39
  }
40
40
  }
package/dist/package.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- "name": "fingerprint-generator",
3
- "version": "2.1.12",
4
- "description": "NodeJS package for generating realistic browser fingerprints.",
5
- "homepage": "https://github.com/apify/fingerprint-suite",
6
- "engines": {
7
- "node": ">=16.0.0"
8
- },
9
- "main": "index.js",
10
- "module": "index.mjs",
11
- "types": "index.d.ts",
12
- "exports": {
13
- ".": {
14
- "import": "./index.mjs",
15
- "require": "./index.js",
16
- "types": "./index.d.ts"
17
- }
18
- },
19
- "scripts": {
20
- "build": "npm run clean && npm run compile",
21
- "postbuild": "cp -r src/data_files && cp ../../README.md ",
22
- "clean": "rimraf ./dist",
23
- "compile": "tsc -p tsconfig.build.json && gen-esm-wrapper ./index.js ./index.mjs",
24
- "copy": "ts-node -T ../../scripts/copy.ts"
25
- },
26
- "repository": {
27
- "type": "git",
28
- "url": "git+https://github.com/apify/fingerprint-suite.git"
29
- },
30
- "author": "Apify",
31
- "license": "Apache-2.0",
32
- "bugs": {
33
- "url": "https://github.com/apify/fingerprint-suite/issues"
34
- },
35
- "dependencies": {
36
- "generative-bayesian-network": "^2.1.10",
37
- "header-generator": "^2.1.12",
38
- "tslib": "^2.4.0"
39
- }
40
- }
package/src/constants.ts DELETED
@@ -1,2 +0,0 @@
1
- export const STRINGIFIED_PREFIX = '*STRINGIFIED*' as const;
2
- export const MISSING_VALUE_DATASET_TOKEN = '*MISSING_VALUE*' as const;
@@ -1,249 +0,0 @@
1
- import { HeaderGenerator, HeaderGeneratorOptions, Headers } from 'header-generator';
2
- import { BayesianNetwork, utils } from 'generative-bayesian-network';
3
- import { MISSING_VALUE_DATASET_TOKEN, STRINGIFIED_PREFIX } from './constants';
4
-
5
- export type ScreenFingerprint = {
6
- availHeight: number;
7
- availWidth: number;
8
- availTop: number;
9
- availLeft: number;
10
- colorDepth: number;
11
- height: number;
12
- pixelDepth: number;
13
- width: number;
14
- devicePixelRatio: number;
15
- pageXOffset: number;
16
- pageYOffset: number;
17
- innerHeight: number;
18
- outerHeight: number;
19
- outerWidth: number;
20
- innerWidth: number;
21
- screenX: number;
22
- clientWidth: number;
23
- clientHeight: number;
24
- hasHDR: boolean;
25
- }
26
-
27
- export type NavigatorFingerprint = {
28
- userAgent: string;
29
- userAgentData: Record<string, string>;
30
- doNotTrack: string;
31
- appCodeName: string;
32
- appName: string;
33
- appVersion: string;
34
- oscpu: string;
35
- webdriver: string;
36
- language: string;
37
- languages: string[];
38
- platform: string;
39
- deviceMemory?: number; // Firefox does not have deviceMemory available
40
- hardwareConcurrency: number;
41
- product: string;
42
- productSub: string;
43
- vendor: string;
44
- vendorSub: string;
45
- maxTouchPoints?: number;
46
- extraProperties: Record<string, string>;
47
- }
48
-
49
- export type VideoCard = {
50
- renderer: string;
51
- vendor: string;
52
- }
53
-
54
- export type Fingerprint = {
55
- screen: ScreenFingerprint;
56
- navigator: NavigatorFingerprint;
57
- videoCodecs: Record<string, string>;
58
- audioCodecs: Record<string, string>;
59
- pluginsData: Record<string, string>;
60
- battery?: Record<string, string>;
61
- videoCard: VideoCard;
62
- multimediaDevices: string[];
63
- fonts: string[];
64
- }
65
-
66
- export type BrowserFingerprintWithHeaders = {
67
- headers: Headers;
68
- fingerprint: Fingerprint;
69
- }
70
- export interface FingerprintGeneratorOptions extends HeaderGeneratorOptions {
71
- /**
72
- * Defines the screen dimensions of the generated fingerprint.
73
- *
74
- * **Note:** Using this option can lead to a substantial performance drop (~0.0007s/fingerprint -> ~0.03s/fingerprint)
75
- */
76
- screen: {
77
- minWidth?: number;
78
- maxWidth?: number;
79
- minHeight?: number;
80
- maxHeight?: number;
81
- };
82
- }
83
-
84
- /**
85
- * Fingerprint generator - Class for realistic browser fingerprint generation.
86
- */
87
- export class FingerprintGenerator extends HeaderGenerator {
88
- fingerprintGeneratorNetwork: any;
89
- fingerprintGlobalOptions: Partial<Omit<FingerprintGeneratorOptions, keyof HeaderGeneratorOptions>>;
90
-
91
- /**
92
- * @param options Default header generation options used - unless overridden.
93
- */
94
- constructor(options: Partial<FingerprintGeneratorOptions> = {}) {
95
- super(options);
96
- this.fingerprintGlobalOptions = {
97
- screen: options.screen,
98
- };
99
- this.fingerprintGeneratorNetwork = new BayesianNetwork({ path: `${__dirname}/data_files/fingerprint-network-definition.zip` });
100
- }
101
-
102
- /**
103
- * Generates a fingerprint and a matching set of ordered headers using a combination of the default options specified in the constructor
104
- * and their possible overrides provided here.
105
- * @param options Overrides default `FingerprintGenerator` options.
106
- * @param requestDependentHeaders Specifies known values of headers dependent on the particular request.
107
- */
108
- getFingerprint(
109
- options: Partial<FingerprintGeneratorOptions> = {},
110
- requestDependentHeaders: Headers = {},
111
- ): BrowserFingerprintWithHeaders {
112
- const filteredValues: Record<string, string[]> = {};
113
-
114
- options = {
115
- ...this.fingerprintGlobalOptions,
116
- ...options,
117
- };
118
-
119
- const partialCSP = (() => {
120
- const extensiveScreen = options.screen && Object.keys(options.screen).length !== 0;
121
- const shouldUseExtensiveConstraints = extensiveScreen;
122
-
123
- if (!shouldUseExtensiveConstraints) return undefined;
124
-
125
- filteredValues.screen = extensiveScreen
126
- ? this.fingerprintGeneratorNetwork.nodesByName.screen.possibleValues.filter((screenString: string) => {
127
- const screen = JSON.parse(screenString.split(STRINGIFIED_PREFIX)[1]);
128
- return (screen.width >= (options.screen?.minWidth ?? 0)
129
- && screen.width <= (options.screen?.maxWidth ?? 1e5)
130
- && screen.height >= (options.screen?.minHeight ?? 0)
131
- && screen.height <= (options.screen?.maxHeight ?? 1e5));
132
- })
133
- : undefined;
134
-
135
- return utils.getPossibleValues(this.fingerprintGeneratorNetwork, filteredValues);
136
- })();
137
-
138
- while (true) {
139
- // Generate headers consistent with the inputs to get input-compatible user-agent and accept-language headers needed later
140
- const headers = super.getHeaders(options, requestDependentHeaders, partialCSP?.userAgent);
141
- const userAgent = 'User-Agent' in headers ? headers['User-Agent'] : headers['user-agent'];
142
-
143
- // Generate fingerprint consistent with the generated user agent
144
- const fingerprint: Record<string, any> = this.fingerprintGeneratorNetwork.generateConsistentSampleWhenPossible({
145
- ...filteredValues,
146
- userAgent: [userAgent],
147
- });
148
-
149
- /* Delete any missing attributes and unpack any object/array-like attributes
150
- * that have been packed together to make the underlying network simpler
151
- */
152
- for (const attribute of Object.keys(fingerprint)) {
153
- if (fingerprint[attribute] === MISSING_VALUE_DATASET_TOKEN) {
154
- fingerprint[attribute] = null;
155
- } else if (fingerprint[attribute].startsWith(STRINGIFIED_PREFIX)) {
156
- fingerprint[attribute] = JSON.parse(fingerprint[attribute].slice(STRINGIFIED_PREFIX.length));
157
- }
158
- }
159
-
160
- if (!fingerprint.screen) continue; // fix? sometimes, fingerprints are generated 90% empty/null. This is just a workaround.
161
-
162
- // Manually add the set of accepted languages required by the input
163
- const acceptLanguageHeaderValue = 'Accept-Language' in headers ? headers['Accept-Language'] : headers['accept-language'];
164
- const acceptedLanguages = [];
165
- for (const locale of acceptLanguageHeaderValue.split(',')) {
166
- acceptedLanguages.push(locale.split(';')[0]);
167
- }
168
- fingerprint.languages = acceptedLanguages;
169
-
170
- return {
171
- fingerprint: this.transformFingerprint(fingerprint),
172
- headers,
173
- };
174
- }
175
- }
176
-
177
- /**
178
- * Transforms fingerprint to the final scheme, more suitable for fingerprint manipulation and injection.
179
- * This schema is used in the `fingerprint-injector`.
180
- * @param fingerprint Fingerprint to be transformed.
181
- * @returns Transformed fingerprint.
182
- */
183
- private transformFingerprint(fingerprint: Record<string, any>): Fingerprint {
184
- const {
185
- userAgent,
186
- userAgentData,
187
- doNotTrack,
188
- appCodeName,
189
- appName,
190
- appVersion,
191
- oscpu,
192
- webdriver,
193
- languages,
194
- platform,
195
- deviceMemory,
196
- hardwareConcurrency,
197
- product,
198
- productSub,
199
- vendor,
200
- vendorSub,
201
- maxTouchPoints,
202
- extraProperties,
203
- screen,
204
- pluginsData,
205
- audioCodecs,
206
- videoCodecs,
207
- battery,
208
- videoCard,
209
- multimediaDevices,
210
- fonts,
211
- } = fingerprint;
212
- const parsedMemory = parseInt(deviceMemory, 10);
213
- const parsedTouchPoints = parseInt(maxTouchPoints, 10);
214
-
215
- const navigator = {
216
- userAgent,
217
- userAgentData,
218
- language: languages[0],
219
- languages,
220
- platform,
221
- deviceMemory: Number.isNaN(parsedMemory) ? null : parsedMemory, // Firefox does not have deviceMemory available
222
- hardwareConcurrency: parseInt(hardwareConcurrency, 10),
223
- maxTouchPoints: Number.isNaN(parsedTouchPoints) ? 0 : parsedTouchPoints,
224
- product,
225
- productSub,
226
- vendor,
227
- vendorSub,
228
- doNotTrack,
229
- appCodeName,
230
- appName,
231
- appVersion,
232
- oscpu,
233
- extraProperties,
234
- webdriver,
235
- };
236
-
237
- return {
238
- screen,
239
- navigator,
240
- audioCodecs,
241
- videoCodecs,
242
- pluginsData,
243
- battery,
244
- videoCard,
245
- multimediaDevices,
246
- fonts,
247
- } as Fingerprint;
248
- }
249
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './fingerprint-generator';
2
- export { PRESETS, HeaderGeneratorOptions, Headers } from 'header-generator';
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.build.json",
3
- "compilerOptions": {
4
- "outDir": "./dist"
5
- },
6
- "include": ["src/**/*"]
7
- }
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "include": ["src/**/*"]
4
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes