Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ import { newInjectedPage } from 'fingerprint-injector';
})();
```

## Environment Variables

The following environment variables can be used to customize file paths used by the fingerprinting tools:

- `FINGERPRINT_NETWORK_DEFINITION_PATH`: Custom path to the fingerprint network definition zip file. If not set, defaults to the bundled file in `fingerprint-generator`. The default file can be found at `fingerprint-generator/data_files/fingerprint-network-definition.zip`.
- `FINGERPRINT_INJECTOR_UTILS_PATH`: Custom path to the fingerprint injector utils.js file. If not set, defaults to the bundled file in `fingerprint-injector`. The default file can be found at `fingerprint-injector/utils.js`.

You can copy these files to custom locations and provide their paths via these environment variables if needed.

## Support

If you find any bug or issue with any of the fingerprinting tools, please [submit an issue on GitHub](https://github.com/apify/fingerprint-suite/issues).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class FingerprintGenerator extends HeaderGenerator {
slim: options.slim,
};
this.fingerprintGeneratorNetwork = new BayesianNetwork({
path: `${__dirname}/data_files/fingerprint-network-definition.zip`,
path: process.env.FINGERPRINT_NETWORK_DEFINITION_PATH || `${__dirname}/data_files/fingerprint-network-definition.zip`,
});
}

Expand Down
8 changes: 6 additions & 2 deletions packages/fingerprint-injector/src/fingerprint-injector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync } from 'fs';
import { readFileSync, existsSync } from 'fs';

import {
BrowserFingerprintWithHeaders,
Expand Down Expand Up @@ -310,8 +310,12 @@ export class FingerprintInjector {
* causing errors when executing it in the browser.
*/
private _loadUtils(): string {
const path = process.env.FINGERPRINT_INJECTOR_UTILS_PATH || `${__dirname}/utils.js`
if (!existsSync(path)) {
throw new Error(`Unable to find ${path}`);
}
// path.join would be better here, but Vercel's build system doesn't like it (https://github.com/apify/fingerprint-suite/issues/135)
const utilsJs = readFileSync(`${__dirname}/utils.js`);
const utilsJs = readFileSync(path);
return `\n${utilsJs}\n`;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/generative-bayesian-network/src/bayesian-network.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AdmZip = require('adm-zip');
import { existsSync } from 'fs';

import { BayesianNode } from './bayesian-node';

Expand All @@ -13,6 +14,9 @@ export class BayesianNetwork {
private nodesByName: Record<string, BayesianNode> = {};

constructor({ path }: { path: string }) {
if (!existsSync(path)) {
throw new Error(`Unable to find ${path}`);
}
const zip = new AdmZip(path);
const zipEntries = zip.getEntries();

Expand Down
Loading