简体   繁体   中英

ReferenceError navigator is not defined for FingerprintJS

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: 登录终端

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)
    } 
})

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 ie, 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)
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM