ReferenceError navigator is not defined for FingerprintJS

4.5k Views Asked by At

I am trying to acquire browser fingerprint with the help of fingerprintjs2, an npm module in Javascript. But it gives me following error:-

ReferenceError: navigator is not defined

Logs: Logs on terminal

Code:

const Fingerprint = require('fingerprintjs2');
const express = require('express');
const cors = require('cors');
const mysql = require('mysql');
const app = express();

const fpInstance = new Fingerprint();
fpInstance.get((result,err)=>{
    if(err){
        console.log('Error obtained',err)
    }
    else{
        console.log(result)
    } 
})
1

There are 1 best solutions below

0
On BEST ANSWER

I have found that fingerprintjs2 is a Javascript Library, doesn't work fine in Node.js. Luckily, a server-side version of the same has been released i.e, Fingerprint express middleware which is used for so called Passive fingerprinting.

Installation: npm install express-fingerprint

Usage:

var Fingerprint = require('express-fingerprint')

app.use(Fingerprint({
    parameters:[
        // Defaults
        Fingerprint.useragent,
        Fingerprint.acceptHeaders,
        Fingerprint.geoip,

        // Additional parameters
        function(next) {
            // ...do something...
            next(null,{
            'param1':'value1'
            })
        },
        function(next) {
            // ...do something...
            next(null,{
            'param2':'value2'
            })
        },
    ]
}))

app.get('*',function(req,res,next) {
    // Fingerprint object
    console.log(req.fingerprint)
})