How to get browser fingerprint from clientJS in react application?

6.8k Views Asked by At

I am trying to get the browser fingerprint from react application using clientJS. When I import clientJS module and try to access get fingerprint function, it's throwing error saying Get Finger Print is not a function. But If i create a clientJS instance from window.ClientJS(). I am able to generate the fingerprint. Why am i not able get the fingerprint function from instance of ClientJS?

Not working

import ClientJS from "clientjs";

const client = new ClientJS()

const fingerPrint = client.getFingerprint()

console.log(client)

enter image description here Working

import ClientJS from "clientjs";

const client = new ClientJS()
const windowClient = new window.ClientJS();

const fingerPrint = windowClient.getFingerprint()

console.log(windowClient);

enter image description here

3

There are 3 best solutions below

1
successtar On

I haven't done much with client Js but I have a tiny package I built that you can use to get a browser fingerprint with ease.

You can use it in any of your frontend application.

It is available here https://github.com/successtar/browser-signature

0
Ante On

Code below is working for me in React.

import ClientJS from 'clientjs';

var client = new ClientJS();

client.getBrowser()
0
Taher On

This worked for me in a react application

import ClientJS from 'clientjs'
import { useState, useEffect } from 'react'

let clientJs: any

const MyComponent = () => {
   const [fingerprint, setFingerprint] = useState('')
   
   useEffect(() => {
     clientJs = new ClientJS()
   }, []) // initiate on the first load

   setFingerprint(clientJs.getFingerprint)
}