Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get fingerprint2 result like function

I want to make a function that get the reslt of fingerprint2.js

Fingerprint2 is a Modern & flexible browser fingerprinting library http://valve.github.io/fingerprintjs2/ Usage:

new Fingerprint2().get(function(result, components){
  console.log(result); //a hash, representing your device fingerprint
  console.log(components); // an array of FP components
});

whatever try i did to get result of Fingerprint2 outside of new Fingerprint2().get(function(result, components){ was failed. like Global vars and cookie because Fingerprint2().get(...) is asynchronous Can it be written like a function to get fingerprint2 result? for example:

var secure = getmefingerprint2();
like image 234
محمد علی پور فتحکوهی Avatar asked Oct 08 '16 13:10

محمد علی پور فتحکوهی


2 Answers

Leverage with ES2017 feature async/await, you can use Fingerprint2.getPromise() like this:

(async () => {
    const components = await Fingerprint2.getPromise();
    const values = components.map(component => component.value);
    const murmur = Fingerprint2.x64hash128(values.join(""), 31);
    console.log('fingerprint:', murmur);
)()

See get and getPromise in Fingerprint2 Doc

like image 92
陈柏林 Avatar answered Nov 16 '22 06:11

陈柏林


This should be a comment but its a bit long.

Even if it were possible, you would be bypassing the published api, meaning you would have to maintain a fork of the original code. You would also need to invoke the functionality synchronously - and fingerprintjs2 runs asynchronously for good and obvious reasons.

You seem to be asking about an XY problem

How you should sole it depends on what you intend to do with the fingerprint after it has been captured.

like image 32
symcbean Avatar answered Nov 16 '22 05:11

symcbean