get-browser-fingerprint
Advanced tools
Comparing version 1.0.2 to 1.1.0
{ | ||
"name": "get-browser-fingerprint", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"author": "Damiano Barbati <damiano.barbati@gmail.com> (http://github.com/damianobarbati)", | ||
@@ -10,8 +10,8 @@ "repository": "https://github.com/damianobarbati/get-browser-fingerprint", | ||
"scripts": { | ||
"test": "node --experimental-modules src/index.spec.js || echo 'test failed'" | ||
"test": "node src/index.spec.js || echo 'test failed'" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^6.6.0", | ||
"puppeteer": "^2.0.0" | ||
"eslint": "^7.8.1", | ||
"puppeteer": "^5.2.1" | ||
} | ||
} |
# get-browser-fingerprint | ||
This package exports a single function computing a browser fingerprint once executed. | ||
No dependency. | ||
Zero dependencies package exporting a single function which computes a browser fingerprint. | ||
## Usage | ||
``` | ||
Get browser fingerprint: | ||
```javascript | ||
import getBrowserFingerprint from 'get-browser-fingerprint'; | ||
const fingerprint = getBrowserFingerprint(); | ||
console.log(fingerprint); | ||
// | ||
``` | ||
``` | ||
Get a "stable" browser fingerprint across os/browser updates taking into account only hardware: | ||
```javascript | ||
import getBrowserFingerprint from 'get-browser-fingerprint'; | ||
const fingerprint = getBrowserFingerprint(true); | ||
console.log(fingerprint); | ||
``` |
@@ -1,2 +0,2 @@ | ||
export default () => { | ||
export default hardwareOnly => { | ||
const { userAgent, language, languages, platform, hardwareConcurrency, deviceMemory } = window.navigator; | ||
@@ -8,3 +8,2 @@ const plugins = Object.entries(window.navigator.plugins).map(([, plugin]) => plugin.name); | ||
const touchSupport = 'ontouchstart' in window; | ||
const canvas = (() => { | ||
@@ -32,18 +31,29 @@ try { | ||
const data = JSON.stringify({ | ||
userAgent, | ||
language, | ||
languages, | ||
platform, | ||
hardwareConcurrency, | ||
deviceMemory, | ||
plugins, | ||
colorDepth, | ||
availWidth, | ||
availHeight, | ||
timezoneOffset, | ||
timezone, | ||
touchSupport, | ||
canvas, | ||
}); | ||
const data = hardwareOnly ? | ||
JSON.stringify({ | ||
platform, | ||
hardwareConcurrency, | ||
deviceMemory, | ||
colorDepth, | ||
availWidth, | ||
availHeight, | ||
touchSupport, | ||
canvas, | ||
}) : | ||
JSON.stringify({ | ||
userAgent, | ||
language, | ||
languages, | ||
platform, | ||
hardwareConcurrency, | ||
deviceMemory, | ||
plugins, | ||
colorDepth, | ||
availWidth, | ||
availHeight, | ||
timezoneOffset, | ||
timezone, | ||
touchSupport, | ||
canvas, | ||
}); | ||
@@ -113,2 +123,2 @@ const murmurhash3_32_gc = key => { | ||
return result; | ||
}; | ||
}; |
@@ -6,9 +6,21 @@ import { strict as assert } from 'assert'; | ||
(async () => { | ||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
const result = await page.evaluate(getBrowserFingerprint); | ||
await browser.close(); | ||
await (async () => { | ||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
const result = await page.evaluate(getBrowserFingerprint); | ||
await browser.close(); | ||
assert.deepStrictEqual(Number.isInteger(result), true, 'fingerprint is not an integer'); | ||
assert.deepStrictEqual(String(result).length > 7, true, 'fingerprint is not long enough'); | ||
})().then(console.log).catch(console.error).finally(process.exit); | ||
assert.deepStrictEqual(Number.isInteger(result), true, 'fingerprint is not an integer'); | ||
assert.deepStrictEqual(String(result).length > 7, true, 'fingerprint is not long enough'); | ||
})(); | ||
await (async () => { | ||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
const result = await page.evaluate(getBrowserFingerprint, true); | ||
await browser.close(); | ||
assert.deepStrictEqual(Number.isInteger(result), true, 'fingerprint is not an integer'); | ||
assert.deepStrictEqual(String(result).length > 7, true, 'fingerprint is not long enough'); | ||
})(); | ||
})().then(console.log).catch(console.error).finally(process.exit); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
6481
6
127
20
0