get-browser-fingerprint 2.1.1 → 3.1.0

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,19 +1,24 @@
1
1
  {
2
2
  "name": "get-browser-fingerprint",
3
- "version": "2.1.1",
3
+ "version": "3.1.0",
4
4
  "author": "Damiano Barbati <damiano.barbati@gmail.com> (https://github.com/damianobarbati)",
5
5
  "repository": "https://github.com/damianobarbati/get-browser-fingerprint",
6
6
  "license": "MIT",
7
7
  "main": "src/index.js",
8
+ "files": [
9
+ "README.md",
10
+ "package.json",
11
+ "src/index.js"
12
+ ],
8
13
  "type": "module",
9
14
  "scripts": {
10
15
  "eslint": "eslint --ignore-path .gitignore --fix",
11
- "test": "NODE_OPTIONS='--experimental-vm-modules' jest --runInBand --no-cache"
16
+ "test": "vitest run"
12
17
  },
13
18
  "devDependencies": {
14
- "eslint-config-xs": "^1.3.0",
19
+ "eslint-config-xs": "^2.6.1",
15
20
  "http-server": "^14.1.1",
16
- "jest": "^28.1.3",
17
- "puppeteer": "^16.1.1"
21
+ "puppeteer": "^21.4.1",
22
+ "vitest": "^0.34.6"
18
23
  }
19
24
  }
package/src/index.js CHANGED
@@ -1,10 +1,5 @@
1
1
  const getBrowserFingerprint = ({ hardwareOnly = false, enableWebgl = false, debug = false } = {}) => {
2
- const devicePixelRatio = +parseInt(window.devicePixelRatio);
3
-
4
2
  const {
5
- appName,
6
- appCodeName,
7
- appVersion,
8
3
  cookieEnabled,
9
4
  deviceMemory,
10
5
  doNotTrack,
@@ -13,17 +8,15 @@ const getBrowserFingerprint = ({ hardwareOnly = false, enableWebgl = false, debu
13
8
  languages,
14
9
  maxTouchPoints,
15
10
  platform,
16
- product,
17
- productSub,
18
11
  userAgent,
19
12
  vendor,
20
- vendorSub,
21
13
  } = window.navigator;
22
14
 
23
15
  const { width, height, colorDepth, pixelDepth } = window.screen;
24
16
  const timezoneOffset = new Date().getTimezoneOffset();
25
17
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
26
18
  const touchSupport = 'ontouchstart' in window;
19
+ const devicePixelRatio = window.devicePixelRatio;
27
20
 
28
21
  const canvas = getCanvasID(debug);
29
22
  const webgl = enableWebgl ? getWebglID(debug) : undefined; // undefined will remove this from the stringify down here
@@ -46,9 +39,6 @@ const getBrowserFingerprint = ({ hardwareOnly = false, enableWebgl = false, debu
46
39
  width,
47
40
  })
48
41
  : JSON.stringify({
49
- appCodeName,
50
- appName,
51
- appVersion,
52
42
  canvas,
53
43
  colorDepth,
54
44
  cookieEnabled,
@@ -62,14 +52,11 @@ const getBrowserFingerprint = ({ hardwareOnly = false, enableWebgl = false, debu
62
52
  maxTouchPoints,
63
53
  pixelDepth,
64
54
  platform,
65
- product,
66
- productSub,
67
55
  timezone,
68
56
  timezoneOffset,
69
57
  touchSupport,
70
58
  userAgent,
71
59
  vendor,
72
- vendorSub,
73
60
  webgl,
74
61
  webglInfo,
75
62
  width,
@@ -121,7 +108,8 @@ export const getWebglID = (debug) => {
121
108
 
122
109
  const f =
123
110
  'attribute vec2 attrVertex;varying vec2 varyinTexCoordinate;uniform vec2 uniformOffset;void main(){varyinTexCoordinate=attrVertex+uniformOffset;gl_Position=vec4(attrVertex,0,1);}';
124
- const g = 'precision mediump float;varying vec2 varyinTexCoordinate;void main() {gl_FragColor=vec4(varyinTexCoordinate,0,1);}';
111
+ const g =
112
+ 'precision mediump float;varying vec2 varyinTexCoordinate;void main() {gl_FragColor=vec4(varyinTexCoordinate,0,1);}';
125
113
  const h = ctx.createBuffer();
126
114
 
127
115
  ctx.bindBuffer(ctx.ARRAY_BUFFER, h);
@@ -175,10 +163,10 @@ export const getWebglInfo = () => {
175
163
  const ctx = document.createElement('canvas').getContext('webgl');
176
164
 
177
165
  const result = {
178
- VERSION: ctx.getParameter(ctx.VERSION),
179
- SHADING_LANGUAGE_VERSION: ctx.getParameter(ctx.SHADING_LANGUAGE_VERSION),
180
- VENDOR: ctx.getParameter(ctx.VENDOR),
181
- SUPORTED_EXTENSIONS: ctx.getSupportedExtensions(),
166
+ VERSION: String(ctx.getParameter(ctx.VERSION)),
167
+ SHADING_LANGUAGE_VERSION: String(ctx.getParameter(ctx.SHADING_LANGUAGE_VERSION)),
168
+ VENDOR: String(ctx.getParameter(ctx.VENDOR)),
169
+ SUPORTED_EXTENSIONS: String(ctx.getSupportedExtensions()),
182
170
  };
183
171
 
184
172
  return result;
@@ -196,7 +184,11 @@ export const murmurhash3_32_gc = (key) => {
196
184
  let h1, h1b, k1;
197
185
 
198
186
  for (let i = 0; i < bytes; i++) {
199
- k1 = (key.charCodeAt(i) & 0xff) | ((key.charCodeAt(++i) & 0xff) << 8) | ((key.charCodeAt(++i) & 0xff) << 16) | ((key.charCodeAt(++i) & 0xff) << 24);
187
+ k1 =
188
+ (key.charCodeAt(i) & 0xff) |
189
+ ((key.charCodeAt(++i) & 0xff) << 8) |
190
+ ((key.charCodeAt(++i) & 0xff) << 16) |
191
+ ((key.charCodeAt(++i) & 0xff) << 24);
200
192
  ++i;
201
193
 
202
194
  k1 = ((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;
@@ -244,5 +236,8 @@ export const murmurhash3_32_gc = (key) => {
244
236
  return h1 >>> 0;
245
237
  };
246
238
 
247
- window.getBrowserFingerprint = getBrowserFingerprint;
239
+ if (typeof window !== 'undefined') {
240
+ window.getBrowserFingerprint = getBrowserFingerprint;
241
+ }
242
+
248
243
  export default getBrowserFingerprint;
package/.babelrc DELETED
@@ -1 +0,0 @@
1
- {}
package/.eslintrc DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": [
3
- "eslint-config-xs/react"
4
- ],
5
- "rules": {
6
- "jest/no-done-callback": "off"
7
- }
8
- }
@@ -1,24 +0,0 @@
1
- name: tag
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- jobs:
9
- test:
10
- runs-on: ubuntu-22.04
11
- timeout-minutes: 3
12
- steps:
13
- - name: checkout
14
- uses: actions/checkout@v2
15
-
16
- - name: setup node
17
- uses: actions/setup-node@v2
18
- with:
19
- node-version-file: '.nvmrc'
20
-
21
- - name: test
22
- run: |
23
- yarn install
24
- yarn test
@@ -1,28 +0,0 @@
1
- name: tag
2
-
3
- on:
4
- push:
5
- tags:
6
- - v*
7
-
8
- jobs:
9
- release:
10
- runs-on: ubuntu-22.04
11
- timeout-minutes: 3
12
- steps:
13
- - name: checkout
14
- uses: actions/checkout@v2
15
-
16
- - name: setup node
17
- uses: actions/setup-node@v2
18
- with:
19
- node-version-file: '.nvmrc'
20
- registry-url: https://registry.npmjs.org/
21
-
22
- - name: release
23
- env:
24
- NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
25
- run: |
26
- yarn install
27
- yarn test
28
- npm publish
@@ -1,9 +0,0 @@
1
- <component name="ProjectRunConfigurationManager">
2
- <configuration default="true" type="JavaScriptTestRunnerJest">
3
- <node-interpreter value="project" />
4
- <node-options value="--experimental-vm-modules" />
5
- <working-dir value="" />
6
- <scope-kind value="ALL" />
7
- <method v="2" />
8
- </configuration>
9
- </component>
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- v16.16
package/jest.config.js DELETED
@@ -1,7 +0,0 @@
1
- export default {
2
- testEnvironment: 'node',
3
- clearMocks: true,
4
- collectCoverage: true,
5
- coverageDirectory: 'coverage',
6
- coverageProvider: 'v8',
7
- };
package/src/index.html DELETED
@@ -1,47 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>get-browser-fingerprint demo</title>
5
- </head>
6
- <body>
7
- <h1>get-browser-fingerprint</h1>
8
-
9
- <h2 id="default"></h2>
10
- <h2 id="hardwareOnly"></h2>
11
- <h2 id="enableWebgl"></h2>
12
-
13
- <script type="module">
14
- import getFingerprint from './index.js';
15
-
16
- args_default: {
17
- const t0 = performance.now();
18
- const fingerprint = getFingerprint({ debug: true });
19
- const t1 = performance.now();
20
-
21
- const result = `Fingerprint: ${fingerprint} (computed in ${(t1 - t0).toFixed(0)} ms)`;
22
- console.log(result);
23
- document.getElementById('default').innerText = result;
24
- }
25
-
26
- args_hardwareOnly: {
27
- const t0 = performance.now();
28
- const fingerprint = getFingerprint({ hardwareOnly: true, debug: true });
29
- const t1 = performance.now();
30
-
31
- const result = `Fingerprint with hardwareOnly=true: ${fingerprint} (computed in ${(t1 - t0).toFixed(0)} ms)`;
32
- console.log(result);
33
- document.getElementById('hardwareOnly').innerText = result;
34
- }
35
-
36
- args_enableWebgl: {
37
- const t0 = performance.now();
38
- const fingerprint = getFingerprint({ enableWebgl: true, debug: true });
39
- const t1 = performance.now();
40
-
41
- const result = `Fingerprint with enableWebgl=true: ${fingerprint} (computed in ${(t1 - t0).toFixed(0)} ms)`;
42
- console.log(result);
43
- document.getElementById('enableWebgl').innerText = result;
44
- }
45
- </script>
46
- </body>
47
- </html>
package/src/index.spec.js DELETED
@@ -1,52 +0,0 @@
1
- import puppeteer from 'puppeteer';
2
-
3
- describe('getBrowserFingerprint', () => {
4
- let browser, page;
5
-
6
- beforeAll(async () => {
7
- browser = await puppeteer.launch({
8
- // headless: false,
9
- // devtools: true,
10
- });
11
- page = await browser.newPage();
12
-
13
- await page.addScriptTag({
14
- type: 'module',
15
- path: './src/index.js',
16
- });
17
- });
18
-
19
- afterAll(async () => {
20
- await browser.close();
21
- });
22
-
23
- it('works without args', async () => {
24
- const result = await page.evaluate(() => {
25
- const result = window.getBrowserFingerprint();
26
- return result;
27
- });
28
-
29
- expect(typeof result).toBe('number');
30
- expect(String(result).length).toBeGreaterThanOrEqual(7);
31
- });
32
-
33
- it('works without hardwareOnly=true', async () => {
34
- const result = await page.evaluate(() => {
35
- const result = window.getBrowserFingerprint();
36
- return result;
37
- });
38
-
39
- expect(typeof result).toBe('number');
40
- expect(String(result).length).toBeGreaterThanOrEqual(7);
41
- });
42
-
43
- it('works with enableWebgl=true', async () => {
44
- const result = await page.evaluate(() => {
45
- const result = window.getBrowserFingerprint({ enableWebgl: true });
46
- return result;
47
- });
48
-
49
- expect(typeof result).toBe('number');
50
- expect(String(result).length).toBeGreaterThanOrEqual(7);
51
- });
52
- });
@@ -1,34 +0,0 @@
1
- import { strict as assert } from 'assert';
2
- import puppeteer from 'puppeteer';
3
-
4
- const browser = await puppeteer.launch();
5
- const page = await browser.newPage();
6
-
7
- await page.addScriptTag({
8
- type: 'module',
9
- path: './src/index.js',
10
- });
11
-
12
- await (async () => {
13
- const result = await page.evaluate(() => {
14
- const result = getBrowserFingerprint();
15
- return result;
16
- });
17
-
18
- assert.deepStrictEqual(Number.isInteger(result), true, 'fingerprint is not an integer');
19
- assert.deepStrictEqual(String(result).length > 7, true, 'fingerprint is not long enough');
20
- })();
21
-
22
- await (async () => {
23
- const browser = await puppeteer.launch();
24
- const page = await browser.newPage();
25
- const result = await page.evaluate(() => {
26
- const result = getBrowserFingerprint({ enableWebgl: true });
27
- return result;
28
- });
29
-
30
- assert.deepStrictEqual(Number.isInteger(result), true, 'fingerprint is not an integer');
31
- assert.deepStrictEqual(String(result).length > 7, true, 'fingerprint is not long enough');
32
- })();
33
-
34
- await browser.close();