simple-fingerprint
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "simple-fingerprint", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Simple browser fingerprinting library", | ||
@@ -25,3 +25,6 @@ "main": "src/index.js", | ||
"prettier": "^2.0.5" | ||
}, | ||
"dependencies": { | ||
"js-sha1": "^0.6.0" | ||
} | ||
} |
# simple-fingerprint | ||
Simple browser fingerprinting library | ||
### Installing | ||
```bash | ||
npm install simple-fingerprint | ||
``` | ||
```bash | ||
yarn add simple-fingerprint | ||
``` | ||
### Usage | ||
#### Simple usage | ||
Compute a stable browser fingerprint: | ||
```javascript | ||
import { computeFingerprint } from "simple-fingerprint"; | ||
let fingerprint = await computeFingerprint(); | ||
``` | ||
`computeFingerprint()` returns an SHA1 hash of a fingerprint, e.g., `"2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"`. | ||
#### Advanced usage | ||
Compute components of a fingerprint: | ||
```javascript | ||
import { computeFingerprintComponents } from "simple-fingerprint"; | ||
let components = await computeFingerprintComponents(); | ||
``` | ||
`computeFingerprintComponents()` returns an object with the following properties: | ||
``` | ||
{ | ||
devicePixelRatio: number | null | ||
userAgent: string | null | ||
platform: string | null | ||
plugins: string | null | ||
headers: string | null | ||
dateFormat: string | null | ||
fonts: string | null | ||
batteryCharging: boolean | null | ||
batteryLevel: number | null | ||
canvas2dRender: string | null | ||
webglRenderer: string | null | ||
webglRender: string | null | ||
} | ||
``` | ||
Note that `batteryCharging` and `batteryLevel` are _not_ stable and may change over time. |
@@ -50,4 +50,4 @@ export function getDevicePixelRatio() { | ||
return fonts | ||
.map((font) => `${font}: ${document.fonts.check(`12px "${font}"`)}`) | ||
.filter((font) => document.fonts.check(`12px "${font}"`)) | ||
.join(", "); | ||
} |
@@ -1,2 +0,2 @@ | ||
export function getCanvas2d() { | ||
export function getCanvas2dRender() { | ||
let canvas = document.createElement("canvas"); | ||
@@ -3,0 +3,0 @@ canvas.width = 200; |
@@ -11,4 +11,5 @@ import { | ||
import { getBatteryCharging, getBatteryLevel } from "./battery"; | ||
import { getCanvas2d } from "./canvas2d"; | ||
import { getWebgl, getWebglRenderer } from "./webgl"; | ||
import { getCanvas2dRender } from "./canvas2d"; | ||
import { getWebglRender, getWebglRenderer } from "./webgl"; | ||
import sha1 from "js-sha1"; | ||
@@ -23,3 +24,3 @@ async function runCatching(f) { | ||
export default async function computeFingerprint() { | ||
async function computeStableComponents() { | ||
return { | ||
@@ -33,8 +34,26 @@ devicePixelRatio: await runCatching(getDevicePixelRatio), | ||
fonts: await runCatching(getFonts), | ||
canvas2dRender: await runCatching(getCanvas2dRender), | ||
webglRenderer: await runCatching(getWebglRenderer), | ||
webglRender: await runCatching(getWebglRender), | ||
}; | ||
} | ||
async function computeUnstableComponents() { | ||
return { | ||
batteryCharging: await runCatching(getBatteryCharging), | ||
batteryLevel: await runCatching(getBatteryLevel), | ||
canvas2d: await runCatching(getCanvas2d), | ||
webglRenderer: await runCatching(getWebglRenderer), | ||
webgl: await runCatching(getWebgl), | ||
}; | ||
} | ||
export async function computeFingerprintComponents() { | ||
return { | ||
...(await computeStableComponents()), | ||
...(await computeUnstableComponents()), | ||
}; | ||
} | ||
export async function computeFingerprint() { | ||
let components = await computeStableComponents(); | ||
let concatenated = Object.values(components).map(String).join("\n"); | ||
return sha1(concatenated); | ||
} |
@@ -13,3 +13,3 @@ export function getWebglRenderer() { | ||
export function getWebgl() { | ||
export function getWebglRender() { | ||
let canvas = document.createElement("canvas"); | ||
@@ -16,0 +16,0 @@ canvas.width = 50; |
8738
190
59
1
+ Addedjs-sha1@^0.6.0
+ Addedjs-sha1@0.6.0(transitive)