
The hashed-device-fingerprint-js JavaScript/TypeScript library provides a simple way to generate unique, device-specific hashed fingerprints for both browser and server environments.
By default, it collects data points such as screen resolution, platform details, CPU concurrency, and the user’s IP address. You can also configure the library to include browser user agent and language settings. Beyond these standard attributes, you can append custom data, like a unique user ID, to create a highly customized fingerprint.
How to use it:
1. Install hashed-device-fingerprint-js using a package manager you prefer.
# Yarn $ yarn add hashed-device-fingerprint-js # NPM $ npm install hashed-device-fingerprint-js
2. Import the ‘generateHashedFingerprint’ module.
// Browser
import { generateHashedFingerprint } from 'hashed-device-fingerprint-js';
// Server
const { generateHashedFingerprint } = require('hashed-device-fingerprint-js');3. Generate a fingerprint.
// Browser
generateHashedFingerprint()
.then(hash => console.log('Fingerprint Hash:', hash))
.catch(error => console.error('Error:', error));
// Server
const headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
'accept-language': 'en-US,en;q=0.9',
'x-forwarded-for': '208.109.65.232',
};
generateHashedFingerprint({
environment: 'server',
headers,
})
.then(hash => console.log('Fingerprint Hash:', hash))
.catch(error => console.error('Error:', error));4. Available options.
- saveToCookie (boolean): Saves the hash in a cookie. Default: true.
- cookieExpiryDays (number): Sets cookie expiration in days. Default: 7.
- useUserAgent (boolean): Includes the browser’s user agent. Default: false.
- useLanguage (boolean): Includes the browser’s language. Default: false.
- useScreenResolution (boolean): Includes screen resolution. Default: true.
- usePlatform (boolean): Includes platform information. Default: true.
- useConcurrency (boolean): Includes logical processor count. Default: true.
- useIP (boolean): Fetches and includes the user’s IP. Default: true.
- userIP (string): Manually provides an IP address. Default: null.
- headers (Record<string, string[]>): HTTP headers for server-side use. Default: {}.
- environment (‘browser’ | ‘server’): Specifies the environment. Default: Auto-detected.
- customData (string): Adds custom data to the fingerprint. Default: null.
generateHashedFingerprint({
useUserAgent: true,
useLanguage: true,
useScreenResolution: true,
usePlatform: true,
useConcurrency: true,
// If userIP is null and useIP is true, the IP is fetched using an external API
// If useIP is false, the IP is excluded entirely.
useIP: true,
userIP: null,
saveToCookie: true,
cookieExpiryDays: 7
})





